Dockernginx reverse proxy
Write docker-compose.yml
Nginx:
Image: 17daebd00e2c
Ports:
-80: 80
Volumes:
-/Home/conf/nginx. conf:/etc/nginx. conf
Links:
-Nginx1
-Nginx2
Privileged: true
Nginx1:
Image: 17daebd00e2c
Volumes:
-/Home/www1:/usr/share/nginx/html
Privileged: true
Nginx2:
Image: 17daebd00e2c
Volumes:
-/Home/www2:/usr/share/nginx/html
Privileged: true
Compile nginx. conf
Add
Upstream pro {
Ip_hash; // access by ip address, which can be annotated during testing
Server nginx1: 80;
Server nginx2: 80;
}
Add
Location /{
Proxy_pass http: // pro;
# Proxy_redirect off;
# If the port is not port 80, set it to Host $ host: port number to transmit the user information received by the proxy server to the real server.
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Client_max_body_size 10 m;
Client_body_buffer_size 128 k;
Proxy_connect_timeout 300;
Proxy_send_timeouts 300;
Proxy_read_timeout 300;
Proxy_buffer_size 4 k;
Proxy_buffers 4 32 k;
Proxy_busy_buffers_size 64 k;
Proxy_temp_file_write_size 64 k;
Add_header Access-Control-Allow-Origin *;
}
Add the html file to the www1 and www2 directories.
Access the html address directly.
Nginx1 and nginx2 can only be accessed in the docker container
The above is the details of the docker nginx Reverse proxy. For more information, see other related articles in the first PHP community!