Skip to content

Instantly share code, notes, and snippets.

@aerohit
Created November 17, 2016 00:29
Show Gist options
  • Save aerohit/2030e768cfdd534277d439732a1e3154 to your computer and use it in GitHub Desktop.
Save aerohit/2030e768cfdd534277d439732a1e3154 to your computer and use it in GitHub Desktop.
# Check the /etc/hosts file too.
server {
# The servers are distinguished by the paths
# Domain is same, but paths are different
# Supports request of the urls:
# http://prodapp.com/nodehost/hostandtime
# http://prodapp.com/node01/hostandtime
# http://prodapp.com/node02/hostandtime
server_name prodapp.com;
location /nodehost/ {
rewrite ^/nodehost(.*) $1 break;
proxy_pass http://127.0.0.1:4000;
}
location /node01/ {
rewrite ^/node01(.*) $1 break;
proxy_pass http://127.0.0.1:8001;
}
location /node02/ {
rewrite ^/node02(.*) $1 break;
proxy_pass http://127.0.0.1:8002;
}
}
# Different domains for each of the servers.
# nodehost.prodapp.com node01.prodapp.com node02.prodapp.com
server {
listen 80;
server_name nodehost.prodapp.com;
location / {
proxy_pass http://127.0.0.1:4000;
}
}
server {
listen 80;
server_name node01.prodapp.com;
location / {
proxy_pass http://127.0.0.1:8001;
}
}
server {
listen 80;
server_name node02.prodapp.com;
location / {
proxy_pass http://127.0.0.1:8002;
}
}
# Load balancing
upstream loadbalancedapp {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
}
server {
#listen 80;
server_name loadbalanced.prodapp.com;
location / {
proxy_pass http://loadbalancedapp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment