Recently, I used Docker in my project. I found that docker container is really useful and can be used to manage various resources and projects in a unified manner.

In practice, we encounter the following problem (all the following applications are launched in Docker) :

Found a pit when using nginx to reverse proxy a service in Docker, record it yourself. Also for everyone to encounter similar problems can refer to.

To find out how nginx reverse-proxies the Web administrator of Rabbit MQ, the following configuration will be unified:

server { listen 80; server_name www.xxxxx.com; location / { client_body_buffer_size 128k; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 16 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_connect_timeout 30s; proxy_pass http://localhost:15672; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}Copy the code

If you simply write the configuration file in nginx.conf like this, a 404 page will appear when accessing it.

The IP address of the service started in different Docker containers is different. Therefore, you cannot reverse proxy the service to localhost or 127.0.0.1. Find the IP address assigned by the container in docker and replace the address in proxy_pass in nginx.conf

Docker inspect rabbitmq

Then simply follow Networks -> Bridge ->IPAddress to find the actual container IP

Replace the IP address in redis. Conf and restart the Redis service. The reverse proxy is displayed on the WEB page.