problem
Visit nginx 502 bad gateway
connect() failed (111: Connection refused)while connecting to upstream
Possible causes 1 docker network problems
The bridge used by docker nginx container (default), and the forwarded service and nginx are on the same machine, but not in the same container, and nginx.conf proxy_pass
is localhost/127.0.0.1
Solution 1:
proxy_pass
use intranet (starting with 172/10)/public address IP addr
view the address of the machine.
Solution 2:
When starting the nginx container, use --net=host
to specify the same network as the host.
docker run --name some-nginx --net=host -v /home/docker/nginx:/etc/nginx -v /home/docker/nginx/logs:/opt/app/logs -d nginx
Possible question 2 is the service started or not?
Make sure the service starts normally docker ps
check whether the service exists;
Ensure proxy_ The port of pass is consistent with the service port being forwarded. Use telnet IP port
to test
Possible question 3: is the port open
For ECS, if the proxy address is not the local IP address, please open the corresponding port in the corresponding security policy