windows10下面部署nginx(解决文件名中文乱码问题)

  由于开发需要,我们总是需要先在windows环境下面部署项目进行测试,通过之后才会移植到linux系统进行测试部署。

  本篇文章会介绍一下windows终端下面部署nginx WEB服务的一些步骤流程,仅供参考!

一、nginx for windows源码包下载

  http://nginx.org/download/nginx-1.9.9.zip  #作者在部署的时候最新的版本是1.9.9

二、安装

  由于nginx采用的是一种开包即用的模式,所以直接解压缩nginx-1.9.9.zip,然后将获得的nginx-1.9.9文件目录直接放到自己的安装路径。本人存放的路径为:D:Program Files ginx-1.9.9

  然后设置系统的环境变量:

  1.新建nginx的变量名及指向路径

  

  2.添加nginx的变量环境到系统的总环境:

  

  最后应用退出,这样在系统的环境中就可以查看到nginx的环境变量:

 

三、配置

  配置文件在conf目录下面: 

#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;

    #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;
    
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime off;   # 显示本机时间而非 GMT 时间
    gzip  on;
    gzip_comp_level 7;
    gzip_min_length 1024;
    gzip_buffers 4 8k;
    gzip_types text/plain application/javascript text/css ;
    output_buffers 1 32k;
    postpone_output 1460;

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;
        charset gbk,utf8;

        #access_log  logs/host.access.log  main;

        location /soft/ {
            root   E:soft;


            index  index.html index.htm;
        }
        location /ckfinder/ {
            root   D:webprojectckfinder;
            index  ckfinder.html;
        }

        #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;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ .php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
        location ~ .php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        location /phpmyadmin/ {
            root           D:webprojectphpMyAdmin;
            fastcgi_pass   127.0.0.1:9001;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
nginx.conf

  备注:因为windows使用的gbk格式的文件编码,而Linux系统中支持中文的编码则是utf-8.所以为了在windows下面支持文件名中文的正常显示,在http或server段添加下面的代码参数:

  charset gbk,utf8; #注意先后顺序

  

四、nginx使用命令(CMD控制台下命令)

  1.nginx启动:

  start nginx  

  2.nginx重启:

  nginx  -s reload

  3.nginx关闭

  nginx -s stop #快速关闭
  nginx -s quit #正常关闭

  4.日志文件切割

  nginx -s reopen #重启日志文件,即对日志文件进行切割

参考官方文档:http://nginx.org/en/docs/windows.html

原文地址:https://www.cnblogs.com/songqingbo/p/5105296.html