Skip to content

Instantly share code, notes, and snippets.

@pankajred
Forked from BretFisher/README.md
Created September 13, 2017 06:29
Show Gist options
  • Save pankajred/c265830e7ca5e3a7d5ee5971c956b706 to your computer and use it in GitHub Desktop.
Save pankajred/c265830e7ca5e3a7d5ee5971c956b706 to your computer and use it in GitHub Desktop.
Simple Apache + Nginx Reverse Proxy Example in Docker Compose
  1. download these two files to the same directory
  2. docker-compose up
  3. http://localhost should show you "it works" which is apache being reverse-proxied through nginx
  4. docker sets up DNS for web based on compose service name so the nginx front-end can find http://web
  5. proxy is set to listen on public port 80 on host so it'll receive incoming traffic, then push to httpd
version: '3'
services:
proxy:
image: nginx:1.11 # this will use the latest version of 1.11.x
ports:
- '80:80' # expose 80 on host and sent to 80 in container
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
web:
image: httpd # this will use httpd:latest
server {
listen 80;
location / {
proxy_pass http://web;
proxy_redirect off;
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-Host $server_name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment