Skip to content

Instantly share code, notes, and snippets.

@arthurbarros
Forked from atma/nginx.conf
Created May 11, 2016 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurbarros/47f500ef8c9f674d9bbe28d66ca14736 to your computer and use it in GitHub Desktop.
Save arthurbarros/47f500ef8c9f674d9bbe28d66ca14736 to your computer and use it in GitHub Desktop.
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