Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker nginx appear "502".1 upstream server temporarily disabled while connecting to upstream

Tags:

docker

nginx

I use nginx in the docker,this is my nginx configure

server {    listen  80;     server_name saber;

    location / {        
       root /usr/share/nginx;       
       index index.html;
}

    location /saber {       
        proxy_pass http://localhost:8080;   
        proxy_redirect off;     
        proxy_set_header Host $host;    
        proxy_set_header X-Real-IP $remote_addr;        
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        
        proxy_buffer_size 4k;       
        proxy_buffers 4 32k;        
        proxy_busy_buffers_size 64k;    
        proxy_connect_timeout 90;   
    }

}

when I use "http://localhost/saber/blog/getBlog.do" in browser ,browser give me a error with "502". and nginx`s error.log have new.

2017/07/09 05:16:18 [warn] 5#5: *1 upstream server temporarily disabled while connecting to upstream, client: 172.17.0.1, server: saber, request: "GET /saber/blog/getBlog.do HTTP/1.1", upstream: "http://127.0.0.1:8080/saber/blog/getBlog.do", host: "localhost"

I can promise the "http://127.0.0.1:8080/saber/blog/getBlog.do" have response success in browser. I try search answer in other question,i find a answer is "/usr/sbin/setsebool httpd_can_network_connect true",this is question url "nginx proxy server localhost permission denied",but I use the docker in win10,the nginx container dont hava setsebool,because the container dont find SELinux. This all,Thank you in advance.

like image 648
Z.Qng Avatar asked Jul 09 '17 09:07

Z.Qng


1 Answers

Localhost inside each container (like the nginx container) is different from localhost outside on your container. Each container gets its own networking namespace by default. Instead of pointing to localhost, you need to place your containers on the same docker network (not the default bridge network) and use the container or service name with Docker's built in DNS to connect. The target port will also be the container port, not the published port on your host.

like image 132
BMitch Avatar answered Nov 12 '22 16:11

BMitch