【乐优商城】Nginx安装配置 -反向代理实现端口转换

版权声明:此博客为个人博客,不涉及商业用途,仅提供学习参考,内容均来自个人原创以及互联网转载和摘录。 --------------------- 本文来自 路西法Lucifer 的CSDN 博客 ,全文地址请点击: https://blog.csdn.net/qq_37495786/article/details/83447110

 一、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之后,再去浏览器输入域名即可访问了。

猜你喜欢

转载自blog.csdn.net/qq_37495786/article/details/83447110