Windows下Nginx配置文件服务器

下载Nginx,打开网站http://nginx.org/en/download.html

image

选择windows版本下载成功后打开目录,在conf目录下打开nginx.conf

image

编辑niginx配置如下


#user nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

  # worker_connections  1024;

}

http {

    include      mime.types;

    default_type  application/octet-stream;

    add_header Access-Control-Allow-Origin *;

    add_header Access-Control-Allow-Headers X-Requested-With;

    add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;

    #tcp_nopush    on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

    gzip  on;

    # 文件服务器

    server {

        listen      8082;  #监听地址

        server_name  localhost; #服务地址

        charset utf-8; #编码设置

        #access_log  logs/host.access.log  main;

        location / {

            root  D:/upload/;  #文件地址绝对路径

            index test.html index.html;

            add_header Cache-Control "no-cache, must-revalidate";

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page  500 502 503 504  /50x.html;

        location = /50x.html {

            root  html;

        }

    }

}

在D盘建立文件夹upload,并在此目录下添加图片1.jpg,做测试使用

image

启动nginx

image

双击nginx.exe,运行成功后打开浏览器输入http://localhost:8082/1.jpg

image

注意nginx启动时,nginx不能在包含中文的目录下,否则会启动失败!
nginx关闭,进入任务管理器杀掉进程即可。

你可能感兴趣的:(Windows下Nginx配置文件服务器)