Skip to content

Instantly share code, notes, and snippets.

@ajaxray
Created October 29, 2017 12:21
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 ajaxray/d015f6c6d4530b37892abbb529840abf to your computer and use it in GitHub Desktop.
Save ajaxray/d015f6c6d4530b37892abbb529840abf to your computer and use it in GitHub Desktop.
Use NGINX as proxy server for Node ExpressJS application.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name my-app.tld www.my-app.tld;
# Serve assets directly from nginx
location ~ ^/(scripts/|images/|img/|js/|css/|stylesheets/|media/|robots.txt|humans.txt|favicon.ico) {
root /path/to/my-app/public/;
access_log off;
expires 24h;
}
# Serve node_modules static files directly from nginx
location ~ ^/(node_modules/) {
root /path/to/my-app/node_modules/;
access_log off;
expires 7d;
}
location / {
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;
proxy_pass http://127.0.0.1:3000/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment