# The upstream module is the link between Node.js and Nginx. # Upstream is used for proxying requests to other servers. # All requests for / get distributed between any of the servers listed. upstream app_domain.tld { server 127.0.0.1:3001 max_fails=0 fail_timeout=10s weight=1; # Send visitors back to the same server each time. ip_hash; # Enable number of keep-alive connections. keepalive 512; } server { listen YOUR_IP_ADDRESS:80; # Index files. index index.html; server_name domain.tld; # Timeout for closing keep-alive connections. keepalive_timeout 10; # Enable gzip compression. gzip on; gzip_http_version 1.1; gzip_vary on; gzip_comp_level 6; gzip_proxied any; gzip_buffers 16 8k; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; # Max upload size. # client_max_body_size 16M; # Change access and error log files. access_log /home/richard/www/logs/domain.tld-nginx.log; location / { # Set this to your upstream module. proxy_pass http://app_domain.tld; # Proxy headers. proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header X-NginX-Proxy true; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_cache_bypass $http_upgrade; proxy_http_version 1.1; proxy_redirect off; # Go to next upstream after if server down. proxy_next_upstream error timeout http_500 http_502 http_503 http_504; proxy_connect_timeout 5s; # Gateway timeout. proxy_read_timeout 20s; proxy_send_timeout 20s; # Buffer settings. proxy_buffers 8 32k; proxy_buffer_size 64k; } # Serve static files without going through upstreams location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) { root /home/richard/www/sites/domain.tld/public; access_log off; expires 1h; } }