Skip to content

Instantly share code, notes, and snippets.

@l-wagner
Last active January 22, 2021 13:10
Show Gist options
  • Save l-wagner/187f37543a9838c69114197ce61609bb to your computer and use it in GitHub Desktop.
Save l-wagner/187f37543a9838c69114197ce61609bb to your computer and use it in GitHub Desktop.
nginx config example for Node, React, Vue & Python apps. #nginx
// ============== NGINX CONFIG FILE =================
# for several node or uwsgi apps hosted in sub locations
# Forward all HTTP requests to HTTPS
server {
listen 80
server_name www.domain.com domain.com;
return 301 https://$host$request_uri;
}
server {
# for a public HTTP server:
#listen 80;
# for a public HTTPS server:
listen 443 ssl;
server_name domain.com;
ssl_certificate "/path/to/Certificate.crt";
ssl_certificate_key "/path/to/certificate.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# root web app directory. all other paths are relative
root /srv/www;
## This should be in your http block and if it is, it's not needed here.
index index.php;
# home location
location / {
try_files /potential-landing-page/build/index.html =404;
}
# custom error pages
error_page 500 502 503 504 /50x.html;
location = /static-pages/50x.html {
}
location = /50x.html {
root /srv/www/static-pages;
internal;
}
location /get_error {
return 500;
}
location /errors.css {
alias /srv/www/errors.css;
}
# apps
# node app
location /node-app/ {
proxy_pass http://127.0.0.1:[PORT]/;
# everything below is default
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
# python + uwsgi app
location /uwsgi-app {
proxy_pass http://127.0.0.1:PORT/;
}
# forward locations
location /deprecated-app {
return 301 https://igo.mskcc.org/sample-submission;
}
# serve any static files
location ~ ^(/static|/js|/css|/dist|/img) {
try_files /node-app/public/$uri /react-page/build/$uri /vue-page/dist/$uri =404;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment