├── README.md
├── reverse-proxy
├── Dockerfile
├── backend-not-found.html
├── default.conf
├── docker-compose.yml
└── includes
│ └── proxy.conf
├── site1
├── docker-compose.yml
└── index.html
└── site2
├── docker-compose.yml
└── index.html
/README.md:
--------------------------------------------------------------------------------
1 | Docker-compose-Nginx-Reverse-Proxy-II
2 | ===================================
3 |
4 | Tutorial
5 | ---------
6 |
7 | [Docker compose : Nginx reverse proxy with multiple containers](http://www.bogotobogo.com/DevOps/Docker/Docker-Compose-Nginx-Reverse-Proxy-Multiple-Containers.php)
8 |
9 |
--------------------------------------------------------------------------------
/reverse-proxy/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM nginx:1.12
2 |
3 | # default conf for proxy service
4 | COPY ./default.conf /etc/nginx/conf.d/default.conf
5 |
6 | # NOT FOUND response
7 | COPY ./backend-not-found.html /var/www/html/backend-not-found.html
8 |
9 | # Proxy configurations
10 | COPY ./includes/ /etc/nginx/includes/
11 |
--------------------------------------------------------------------------------
/reverse-proxy/backend-not-found.html:
--------------------------------------------------------------------------------
1 |
2 |
Proxy Backend Not Found
3 |
4 | Proxy Backend Not Found
5 |
6 |
--------------------------------------------------------------------------------
/reverse-proxy/default.conf:
--------------------------------------------------------------------------------
1 | # web service1 config.
2 | server {
3 | listen 80;
4 | server_name site1.example.com;
5 |
6 | location / {
7 | include /etc/nginx/includes/proxy.conf;
8 | proxy_pass http://site1_app_1;
9 | }
10 |
11 | access_log off;
12 | error_log /var/log/nginx/error.log error;
13 | }
14 |
15 | # web service2 config.
16 | server {
17 | listen 80;
18 | server_name site2.example.com;
19 |
20 | location / {
21 | include /etc/nginx/includes/proxy.conf;
22 | proxy_pass http://site2_app_1;
23 | }
24 |
25 | access_log off;
26 | error_log /var/log/nginx/error.log error;
27 | }
28 |
29 | # Default
30 | server {
31 | listen 80 default_server;
32 |
33 | server_name _;
34 | root /var/www/html;
35 |
36 | charset UTF-8;
37 |
38 | error_page 404 /backend-not-found.html;
39 | location = /backend-not-found.html {
40 | allow all;
41 | }
42 | location / {
43 | return 404;
44 | }
45 |
46 | access_log off;
47 | log_not_found off;
48 | error_log /var/log/nginx/error.log error;
49 | }
50 |
--------------------------------------------------------------------------------
/reverse-proxy/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 | proxy:
4 | build: ./
5 | networks:
6 | - site1
7 | - site2
8 | ports:
9 | - 80:80
10 |
11 | networks:
12 | site1:
13 | external:
14 | name: site1_default
15 | site2:
16 | external:
17 | name: site2_default
--------------------------------------------------------------------------------
/reverse-proxy/includes/proxy.conf:
--------------------------------------------------------------------------------
1 | proxy_set_header Host $host;
2 | proxy_set_header X-Real-IP $remote_addr;
3 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
4 | proxy_set_header X-Forwarded-Proto $scheme;
5 | proxy_buffering off;
6 | proxy_request_buffering off;
7 | proxy_http_version 1.1;
8 | proxy_intercept_errors on;
--------------------------------------------------------------------------------
/site1/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 | app:
4 | image: nginx:1.12
5 | volumes:
6 | - .:/usr/share/nginx/html/
7 | expose:
8 | - "80"
9 |
--------------------------------------------------------------------------------
/site1/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | site1.example.com
5 |
6 |
7 | site1.example.com
8 |
9 |
10 |
--------------------------------------------------------------------------------
/site2/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 | app:
4 | image: nginx:1.12
5 | volumes:
6 | - .:/usr/share/nginx/html/
7 | expose:
8 | - "80"
9 |
--------------------------------------------------------------------------------
/site2/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | site2.example.com
5 |
6 |
7 | site2.example.com
8 |
9 |
10 |
--------------------------------------------------------------------------------