Skip to content

Instantly share code, notes, and snippets.

@zhaocnus
Last active March 10, 2017 03:40
Show Gist options
  • Select an option

  • Save zhaocnus/fc81a78fc03c4bc294836dd01233d63c to your computer and use it in GitHub Desktop.

Select an option

Save zhaocnus/fc81a78fc03c4bc294836dd01233d63c to your computer and use it in GitHub Desktop.
Nginx config
# Serve static SPA
server {
listen 80;
root /home/young/src/www.example.com/;
index index.html;
server_name www.example.com;
location / {
try_files $uri /index.html =404;
sendfile off;
expires 0;
}
}
# Serve nodejs app
server {
listen 80;
root /home/young/src/www.example.com/;
index index.html;
server_name www.example.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
# set body size
client_max_body_size 2M;
# WebSocket support (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# serve static file from another dir using alias
# http://stackoverflow.com/a/10647080
location /static/ {
autoindex off;
alias /home/young/static/;
}
# serve static file from another dir using root
# http://stackoverflow.com/a/10647080
location /static2/ {
autoindex off;
root /home/young/;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment