Last active
January 13, 2016 18:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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