windows nginx 完整安装配置笔记

准备工作:windows 2016、nginx 1.16.0(zip)、以管理员权限运行操作

1、下载nginx

百度网盘: https://pan.baidu.com/s/1KJFouVOm-Qkyjm721WWvfQ 提取码: 2ccv 

nginx官网:http://nginx.org/en/download.html

2、安装   将压缩包解压到任意(不要含有中文及特殊字符)目录下,这个压缩包默认解压为nginx-1.16.0\nginx-1.16.0\*.*

3、配置:包含多站点或多域名

conf/nginx.conf 记事本等工具打开,内容如下:

#user  root;
worker_processes  auto;

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


    server {
        listen       80;
        server_name  www.XXXX.com.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root html;
            proxy_pass   http://127.0.0.1:8080/webnew/;
            index  index.html index.htm;
          
            client_max_body_size 10m;
            client_body_buffer_size 128k;
            
             proxy_connect_timeout 3;
             proxy_send_timeout 30;
             proxy_read_timeout 30;

             proxy_buffer_size 4k;
             proxy_buffers 4 32k;
             proxy_busy_buffers_size 64k;
             proxy_temp_file_write_size 64k;
        }

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

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    server{
        listen    80;
        server_name file.xxxx.com.cn;
        #tomcat 站点
        location / {
             proxy_pass http://127.0.0.1:8080/files/;
             index index.html index.htm index.jsp;
        }
       # error_page   500 502 503 504  /50x.html;
       # location = /50x.html {
      #      root   html;
     #   }

    }

......

保存后,启动或重启nginx(cmd命令输入界面,进入解压后的根目录(和nginx.exe同级),输入start nginx 或 nginx -s reload)

4、开机自启动

已有文章借鉴:https://www.cnblogs.com/liabin/p/11736113.html

记录步骤:a、下载 winsw-v2.3.0 b、拷贝到解压后的根目录下(和nginx.exe同级)c、改名为 nginx-service.exe d、创建 nginx-service.xml 内容如下 e、添加服务 (cmd命令输入界面,进入解压后的根目录(和nginx.exe同级)运行 nginx-service.exe install

<!-- nginx-service.xml -->
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<logpath>D:\nginx-1.16.0\nginx-1.16.0\</logpath>
<logmode>roll</logmode>
<depend></depend>
<executable>D:\nginx-1.16.0\nginx-1.16.0\nginx.exe</executable>
<stopexecutable>D:\nginx-1.16.0\nginx-1.16.0\nginx.exe -s stop</stopexecutable>
</service>

5、修改系统hosts文件 一般位于 c:\windows\system32\dirvers\etc\hosts,添加内容如下:

127.0.0.1  域名

6、修改hosts 立即生效  在 cmd命令窗口下  运行  ipconfig /flushdns  即可

7、测试  在浏览器中输入对应的域名 访问到对应内容 即为成功!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值