Skip to content

Instantly share code, notes, and snippets.

@xamedow
Created November 30, 2017 16:47
Show Gist options
  • Save xamedow/1a39f397a592f2f35f1de9af575be33f to your computer and use it in GitHub Desktop.
Save xamedow/1a39f397a592f2f35f1de9af575be33f to your computer and use it in GitHub Desktop.
Nginx config template for serving static frontend bundle, along with local api server
upstream http_backend {
# INNER SERVER LOCAL IP:PORT
server 127.0.0.1:1337;
}
server {
listen 80;
server_name #YOUR SERVER IP OR DOMAIN;
# STATIC FRONTEND FILES
location / {
root /home/ # YOUR PATH TO STATIC FILES;
index index.html;
try_files $uri $uri/ /index.html;
}
# PATH TO API THAT IS BEING SERVED FROM INNER LOCAL SERVER
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:1337/api;
proxy_redirect off;
}
# ANOTHER PATH FROM LOCAL SERVER
location /auth {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:1337/auth;
proxy_redirect off;
}
# WORKAROUND TO PREVENT NGINX TO BLOCK LOCAL POST REQUESTS FROM STATIC FILES e.g. login page
error_page 405 =200 "/auth/${uri}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment