Skip to content

Instantly share code, notes, and snippets.

@atombrella
Created April 30, 2019 11:46
Show Gist options
  • Save atombrella/2ed0a1838955b9c6434b90ad22c89b4e to your computer and use it in GitHub Desktop.
Save atombrella/2ed0a1838955b9c6434b90ad22c89b4e to your computer and use it in GitHub Desktop.
docker nginx reverse proxy
# Dockerfile
version: '3.6'
services:
foo:
image: foo
restart: unless-stopped
ports:
- 9030:8080
nginx:
image: nginx:latest
restart: unless-stopped
ports:
- 9090:80
volumes:
- "./nginx:/etc/nginx/conf.d"
depends_on:
- foo
# nginx configuration
server {
listen 80;
server_name localhost;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_request_buffering off;
proxy_http_version 1.1;
proxy_intercept_errors on;
location /foo {
rewrite /foo/(.*) /$1 break;
proxy_pass http://foo:8080; # must match port in the Dockerfile!
}
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