Created
October 3, 2019 21:19
-
-
Save ecelis/d3647d8ba953f3ecb18f936f39c693ea to your computer and use it in GitHub Desktop.
Nginx REST API and SPA configuration
This file contains hidden or 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
map $http_upgrade $connection_upgrade { | |
default upgrade; | |
'' close; | |
} | |
server { | |
listen 80; | |
server_name _; | |
location /api/ { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range'; | |
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH'; | |
proxy_pass http://backend:8000; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
} | |
location / { | |
# Uncomment for production build | |
#root /front; | |
#index index.html index.htm; | |
# Comment line below in production deployment | |
proxy_pass http://spa:3000; | |
proxy_http_version 1.1; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection $connection_upgrade; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /usr/share/nginx/html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment