Skip to content

Instantly share code, notes, and snippets.

@miloplacencia miloplacencia/nginx.conf forked from atma/nginx.conf
Created Feb 11, 2017

Embed
What would you like to do?
Nginx + nodejs + socket.io websockets
# Add to nginx.conf http section
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream some_upsteram_com {
server 127.0.0.1:3000;
keepalive 15;
}
server {
listen 80;
root /home/user/www/public;
index index.html index.htm;
access_log /home/user/logs/site-access.log;
error_log /home/user/logs/site-error.log;
server_name site.com www.site.com;
large_client_header_buffers 8 32k;
location / {
try_files $uri @nodejs;
}
# Important! Serve client socket.io file as normal static file, e.g. /js/libs/socket.io/socket.io.min.js
location /socket.io/ {
proxy_pass http://some_upsteram_com;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_redirect off;
proxy_buffers 8 32k;
proxy_buffer_size 64k;
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;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 30d;
}
location @nodejs {
proxy_pass http://some_upsteram_com;
}
location ~ /\. {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.