- download these two files to the same directory
- docker-compose up
- http://localhost should show you "it works" which is apache being reverse-proxied through nginx
- docker sets up DNS for
web
based on compose service name so the nginx front-end can find http://web - proxy is set to listen on public port 80 on host so it'll receive incoming traffic, then push to httpd
Last active
May 1, 2023 02:28
-
-
Save BretFisher/468bca2900b90a4dddb7fe9a52143fc6 to your computer and use it in GitHub Desktop.
Simple Apache + Nginx Reverse Proxy Example in Docker Compose
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
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 |
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
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
@sarashmishra
This is because , maybe you are using a docker toolbox in windows. The following docker-compose.yml file contains the volumes.. which will only work with docker toolbox in windows ...only if you put the docker-compose.yml and nginx.conf inside the C:/Users// directory.