Created
May 19, 2020 21:03
-
-
Save espretto/97350a1ac8a713997796d212b8a4079a to your computer and use it in GitHub Desktop.
nginx:reverse-proxy
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
# example nginx config | |
# ------------------------------------------------------------------------------ | |
# serve static files from volume mounted at /public | |
# serve backend api expsosed by container "backend" on port 5000 | |
# ------------------------------------------------------------------------------ | |
user nginx; | |
worker_processes 1; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
client_max_body_size 100m; | |
upstream backend { | |
server backend:5000; | |
} | |
server { | |
listen 80; | |
charset utf-8; | |
root /public/; | |
index index.html; | |
# client | |
location / { | |
try_files $uri $uri/ @rewrites; | |
} | |
location @rewrites { | |
rewrite ^(.+)$ /index.html last; | |
} | |
# backend reverse-proxy | |
location ~ ^/api/?(.*)$ { | |
proxy_redirect off; | |
proxy_pass http://backend/$1$is_args$args; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment