Nginx 共享默认http端口
如何使用 nginx 将 http 请求代理到默认端口(例如 80)到同一服务器上不同端口上运行的其他进程。
Add a config file named "myconfig" under /etc/nginx/sites-available
server {
listen 80;
server_name domain1;
location / {
proxy_pass http://0.0.0.0:8080;
include /etc/nginx/proxy_params;
}
}
server {
listen 80;
server_name domain2;
location / {
proxy_pass http://0.0.0.0:8081;
include /etc/nginx/proxy_params;
}
}
Link the config file to /etc/nginx/sites-enabled
$ cd /etc/nginx/sites-enabled
$ ln -s /etc/nginx/sites-available/myconfig myconfig
Restart nginx and you're all set
$ service nginx restart
See this stackoverflow post for reference.