NGINX as proxy
- Apache as webserver behind proxy
Files
~> ls
docker-compose.yml nginx.conf
docker-compose.yml
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
nginx.conf
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;
}
}
Output
~> docker-compose up
Creating network "composesample2_default" with the default driver
Pulling proxy (nginx:1.11)...
1.11: Pulling from library/nginx
6d827a3ef358: Pull complete
f8f2e0556751: Pull complete
5c9972dca3fd: Pull complete
451b9524cb06: Pull complete
Digest: sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582
Status: Downloaded newer image for nginx:1.11
Creating composesample2_web_1 ...
Creating composesample2_proxy_1 ...
Creating composesample2_web_1
Creating composesample2_web_1 ... done
Attaching to composesample2_proxy_1, composesample2_web_1
web_1 | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.20.0.3. Set the 'ServerName' directive globally to suppress this message
web_1 | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.20.0.3. Set the 'ServerName' directive globally to suppress this message
web_1 | [Sun Oct 01 14:31:28.245123 2017] [mpm_event:notice] [pid 1:tid 139638460622720] AH00489: Apache/2.4.27 (Unix) configured -- resuming normal operations
web_1 | [Sun Oct 01 14:31:28.254949 2017] [core:notice] [pid 1:tid 139638460622720] AH00094: Command line: 'httpd -D FOREGROUND'
proxy_1 | 172.20.0.1 - - [01/Oct/2017:14:32:24 +0000] "GET / HTTP/1.1" 200 45 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" "-"
web_1 | 172.20.0.2 - - [01/Oct/2017:14:32:24 +0000] "GET / HTTP/1.0" 200 45
C^
~> docker-compose up -d
Starting composesample2_proxy_1 ...
Starting composesample2_web_1 ...
Starting composesample2_proxy_1
Starting composesample2_proxy_1 ... done
~> docker-compose logs
Attaching to composesample2_proxy_1, composesample2_web_1
...
~> docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------
composesample2_proxy_1 nginx -g daemon off; Up 443/tcp, 0.0.0.0:80->80/tcp
composesample2_web_1 httpd-foreground Up 80/tcp
~> docker-compose top
composesample2_proxy_1
PID USER TIME COMMAND
----------------------------------------------------------------
65775 root 0:00 nginx: master process nginx -g daemon off;
65979 104 0:00 nginx: worker process
composesample2_web_1
PID USER TIME COMMAND
----------------------------------------
65832 root 0:00 httpd -DFOREGROUND
65891 bin 0:00 httpd -DFOREGROUND
65892 bin 0:00 httpd -DFOREGROUND
65893 bin 0:00 httpd -DFOREGROUND
~> docker-compose down
Stopping composesample2_proxy_1 ... done
Stopping composesample2_web_1 ... done
Removing composesample2_proxy_1 ... done
Removing composesample2_web_1 ... done
Removing network composesample2_default