Nginx anti generation Docker internal service (take Wekan as an example)

There are many Docker containers on the server. They do not set port mapping, but use the unified front-end Nginx program to reverse generation. The advantage of this is that internal Docker services can be accessed externally without wasting valuable external ports.

principle

each Docker The container has its own host name and internal IP. Even if no external port mapping is set, there will be corresponding port listening on the internally assigned IP. For example, on my host Wekan The basic information of the container is as follows:

 container_name:wekan-app ip:172.19.0.xxx Network:network_group1(bridge)

Operate another container to add network_group1 Network group, ping Wekan container name in the container:

Then try to access the container's services:

At this time, the two containers can communicate with each other.

operation

1. Container interworking

First prepare an Nginx container and skim over the table.

Then Nginx Container added to Wekan Container. use Protainer This step is very simple. Just select the corresponding network and click Join network That is:

To verify whether the containers can communicate, you can manually ping the wekan container.

2. Modify Wekan configuration

Edit Wekan configuration and set ROOT_URL Change to the access address for external use, such as mywekan.test.com

3. Modify Nginx configuration

The Nginx configuration is modified to increase access address monitoring and reverse forwarding.

Because Wekan used websocket Communication, so you need to add Upgrade Etc.:

 map $http_upgrade $connection_upgrade { default upgrade; ''      close; } server { listen       80; server_name  mywekan.test.com; #access_log /dev/null; #access_log  /var/log/nginx/nginx.localhost.access.log  main; error_log  /var/log/nginx/mywekan.test.com.error.log  warn; location / { proxy_pass  http://wekan-app:8080 ; index  index.html index.htm; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header X-Forwarded-For $remote_addr; } # deny access to .htaccess files,  if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny  all; } }

Other fields can be added as required.

After completion, restart the Nginx container to access mywekan.test.com You can see the effect.

Zimiao haunting blog (azimiao. com) All rights reserved. Please note the link when reprinting: https://www.azimiao.com/6722.html
Welcome to the Zimiao haunting blog exchange group: three hundred and thirteen million seven hundred and thirty-two thousand

Comment

*

*

Comment area

  1. Jason 04-26 10:56 reply

    Hello, can you write an article about migrating Wekan deployed by Docker to another server?
    I have encountered this problem at present, and the installation of the official documentation has not been successful!
    Thank you first!