Skip to content

The reverse proxy cannot obtain the correct IP address #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Kry1702 opened this issue Nov 16, 2021 · 3 comments
Closed

The reverse proxy cannot obtain the correct IP address #600

Kry1702 opened this issue Nov 16, 2021 · 3 comments

Comments

@Kry1702
Copy link

Kry1702 commented Nov 16, 2021

NGINX and backend containers (JAVA) are managed through docker-compose.
They are all connected to the same bridged network.

When the JAVA container is restarted, the port exposed outside of Nginx cannot be accessed and an error 404 is displayed. In fact, the resource actually exists.

Nginx reverse proxy is requesting the wrong IP address, not the actual IP address of the current backend (JAVA) container.
The IP address of the Nginx reverse proxy is always obtained as the expired address last used by the JAVA container.
My stupid solution, restarting the JAVA container together with Nginx, is obviously not the best solution.

More:
The Ping command (ping java-05-server) in the Nginx container returns the correct IP address of the JAVA container.
Nginx Config:proxy_pass http://java-05-server:43021
Docker network custom creation (docker network create app-network).
docker-compose network specified to join the extended network(external: true).
Nginx log: [error] 22#22: *47 connect() failed (111: Connection refused) while connecting to upstream.

Experts, have you encountered similar problems, can you tell me your solution? Thank you!

@yosifkit
Copy link
Contributor

Nginx caches the DNS lookup; to make it look it up all the time, you can put it in a variable or adjust the TTL of the cache: https://serverfault.com/a/593003

@Kry1702
Copy link
Author

Kry1702 commented Nov 17, 2021

Nginx 缓存 DNS 查找;为了让它一直查找,你可以把它放在一个变量中或调整缓存的TTL:https : //serverfault.com/a/593003

Thank you! Based on the solution you provided, I tried it and the problem still exists.
Nginx config changed to
server {
...
resolver 127.0.0.11; #The IP address comes from the nameserver value of the Nginx container /etc/resolv.conf file
set $backend "http://java-05-server:43021";
proxy_pass $backend;
...
}

Thanks again for your reply!

@Kry1702
Copy link
Author

Kry1702 commented Nov 17, 2021

Nginx caches the DNS lookup; to make it look it up all the time, you can put it in a variable or adjust the TTL of the cache: https://serverfault.com/a/593003

Thank you! Based on the ideas you provided, I have successfully solved the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants