Here we go for [b:1a25056ef3]multiple remote servers[/b:1a25056ef3] having [b:1a25056ef3]multiple hostnames[/b:1a25056ef3] (so 1 sites under different hostnames on each backend server)
[code:1:1a25056ef3]
server {
listen 8001 default_server;
server_name user_local;
location / {
root /home/user/www;
}
}
server {
listen 8002 default_server;
server_name web1.example.com;
location / {
proxy_pass http://web1.local:80;
proxy_set_header Host web1.local:80;
}
}
server {
listen 8003 default_server;
server_name web2.example.com;
location / {
proxy_pass http://web2.local:80;
proxy_set_header Host web2.local:80;
}
}
server {
listen 8004 default_server;
server_name web3.example.com;
location / {
proxy_pass http://web3.local:80;
proxy_set_header Host web3.local:80;
}
}
upstream main {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
server 127.0.0.1:8004;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://main;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_404;
}
}[/code:1:1a25056ef3]
Sources:
http://serverfault.com/questions/598202/make-nginx-to-pass-hostname-of-the-upstream-when-reverseproxying
http://stackoverflow.com/questions/13240840/nginx-reverse-proxy-multiple-backends
http://stackoverflow.com/questions/12868683/nginx-proxy-next-upstream-doesnt-work
Leave a Reply