Skip to content

Instantly share code, notes, and snippets.

@mdigan
Last active December 27, 2015 12:09
Show Gist options
  • Save mdigan/7324200 to your computer and use it in GitHub Desktop.
Save mdigan/7324200 to your computer and use it in GitHub Desktop.
# Load balancer configuration
upstream exampleApp {
# Directs to the process with least number of connections.
least_conn;
# One failed response will take a server out of circulation for 20 seconds.
server 127.0.0.1:10080 fail_timeout=20s;
server 127.0.0.1:10081 fail_timeout=20s;
#server 127.0.0.1:10082 fail_timeout=20s;
#server 127.0.0.1:10083 fail_timeout=20s;
}
# WebSocket "upgrade" method
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# Server settings
server {
listen 80;
root /var/www/exampleApp/;
# Make site accessible from http://exampleApp.com/
server_name exampleApp.com;
# Logs
access_log /var/log/nginx/exampleApp_access.log;
error_log /var/log/nginx/exampleApp_error.log;
# pass the request to the node.js server with the correct headers
location / {
# Setting proxy headers
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 true;
proxy_pass http://exampleApp/;
proxy_redirect off;
# WebSocket headers
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment