Skip to content

Instantly share code, notes, and snippets.

@vodolaz095
Last active January 13, 2016 18:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vodolaz095/8373960 to your computer and use it in GitHub Desktop.
Save vodolaz095/8373960 to your computer and use it in GitHub Desktop.
NGINX Config for nodejs application with nginx serving assets and socket.io support
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
# * https://gist.github.com/vodolaz095/8373960
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
gzip on;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name default;
index index.html;
#serve frontend from private directory
root /home/nap/static;
location / {
#if its an actual file, set up cache policies.
if ( -f $request_filename) {
expires max;
add_header Cache-Control public;
}
#default handler, first try to serv the requested file, if file doesn't exists, it request is proxied to nodejs.
try_files $uri @nodejs;
}
location /socket.io/ {
proxy_pass http://example.org;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_upgrade;
}
#this is the nodejs proxy.
location @nodejs {
proxy_pass http://example.org;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment