Nginx to share default http port
How to use nginx to proxy http request to default port (e.g. 80) to other processes running on different ports on the same server.
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.