Nginx安装配置 -反向代理实现端口转换

 一、bind() to 0.0.0.0:80 failed

  原因:

        是由于Windows10系统默认把80端口给占用了,而nginx的端口也是80,所以说报错。

2018/10/27 05:40:15 [emerg] 21724#22312: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)
2018/10/27 05:41:54 [emerg] 15196#14864: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

解决:

1、运行中输入regedit进入注册表;

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP

找到start,原本是3,我这里改成了4.确认之后重启系统。

二、CreateFile() "D:\Program Files (x86)\nginx-1.14.0/logs/nginx.pid" failed (2: The system cannot find the file specified)

       正常情况下D:\Program Files (x86)\nginx-1.14.0/logs/nginx.pid,logs目录下会有nginx.pid文件,也有可能该目录下没有这个文件。如果没有,创建一个空文件。参考:windows系统nginx重启发生异常The system cannot find the file specified

2018/10/27 05:44:47 [error] 7336#12764: CreateFile() "D:\Program Files (x86)\nginx-1.14.0/logs/nginx.pid" failed (2: The system cannot find the file specified)

三、Nginx命令

  • 启动:start nginx.exe

  • 停止:nginx.exe -s stop

  • 重新加载:nginx.exe -s reload

四、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;
    sendfile        on;
   
    keepalive_timeout  65;

    gzip  on;
	server {
        listen       80;
        server_name  manage.leyou.com;

        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        location / {
			proxy_pass http://127.0.0.1:9001;
			proxy_connect_timeout 600;
			proxy_read_timeout 600;
        }
    }
	server {
        listen       80;
        server_name  api.leyou.com;

        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        location / {
			proxy_pass http://127.0.0.1:10010;
			proxy_connect_timeout 600;
			proxy_read_timeout 600;
        }
    }
}

五、start nginx.exe启动命令

六、web项目路径是localhost:9001

浏览器输入命令:localhost:9001

ps:如果每次都去改host文件的话,比较麻烦,当然也可以实现。这里推荐使用SwitchHosts

点击ok之后,再去浏览器输入域名即可访问了。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值