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.

nginx