当前位置:首页>正文

如何给nginx绑定多个端口 如何修改nginx中的端口 listen 8080

2023-04-14 23:02:29 互联网 未知

如何给nginx绑定多个端口

由于linux的socket监听机制和TCP协议,多个进程无法监听同一个端口,但是具体到nginx,可以多个nginx进程监听到不同端口,通过一个主进程端口做upstream来实现负载均衡,这个有点类似于网络的汇聚,可以设置不同的策略,比如iphash,urlhash或者RR。

如何修改nginx中的端口 listen 8080

修改 nginx.conf 文件实现。在 Linux 上该文件的路径为 /usr/local/nginx/conf/nginx.conf,Windows 下 安装目录conf ginx.conf。

1 server {
2 listen 8080
3 server_name localhost
4
5 ……
6 }

改成

01 server {
02 listen 80
03 server_name localhost
04
05 location / {
06 root html
07 index index.html index.htm
08 }
09 ……
10 }