Nginx reverse proxy multiple backends

You can match the different URLs with server {} blocks, then inside each server block, you’d have the reverse proxy settings. Below, an illustration; server { server_name client.example.com; # app1 reverse proxy follow proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://x.x.x.100:80; } server { server_name client2.example.com; # app2 reverse proxy settings follow … Read more

Configure nginx with multiple locations with different root folders on subdomain

You need to use the alias directive for location /static: server { index index.html; server_name test.example.com; root /web/test.example.com/www; location /static/ { alias /web/test.example.com/static/; } } The nginx wiki explains the difference between root and alias better than I can: Note that it may look similar to the root directive at first sight, but the document … Read more

Socket.io with nginx

In a running server, the nginx’s configuration being used here is: # Requests for socket.io are passed on to Node on port 3000 location ~* \.io { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy false; proxy_pass http://localhost:3000; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection “upgrade”; }