我试图在具有相同实例的两个端口上配置nginx,例如在端口80和端口81上,但到目前为止没有运气。这是我想要做的一个例子:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name chat.local.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_buffering off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 81;
server_name console.local.com;
location / {
proxy_pass http://127.0.0.1:8888;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_buffering off;
}
}
}
当我尝试运行console.local.com时,它会显示来自chat.local.com的内容。有没有办法让nginx在两个端口上运行?提前谢谢!
答案 0 :(得分:7)
你的配置看起来不错
我认为问题是这个(如果我错了,请纠正我):
在所有可能的情况下,您都希望更改您的console.local.com以便在端口80上收听:
答案 1 :(得分:3)
你可以简单地添加2次listen语句;如下
听80;
听81;
这应该适用于nginx