Created
November 30, 2017 16:47
-
-
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
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
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