Nginx – reverse proxy nginx bad gateway

centosnginxreverse-proxy

We have a reverse proxy server on nginx for a bamboo server but it gives a 502 bad gateway but accessible from reverse proxy server(both centos).

nginx.conf:

 server {
listen 80;
server_name bamboo.test.foo.com;

access_log  /var/log/nginx/bamboo.test.foo.access.log  main;
  location /bamboo {
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://192.168.10.5:8085;
    client_max_body_size 10M;
   }
proxy_connect_timeout       600;
proxy_send_timeout          600;
proxy_read_timeout          600;
    send_timeout                600;
  }

access log:

81.82.215.59 - - [07/Dec/2016:16:19:39 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36" "-"

81.82.215.59 - - [07/Dec/2016:16:19:39 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://bamboo.test.foo.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36" "-"

Best Answer

I had SELinux enabled, which blocked Nginx from making outbound connections.

You can check this with:

# getenforce

If SELinux is on and you're experiencing this, you might try setting httpd_can_network_connect to true, and then restarting nginx:

# setsebool -P httpd_can_network_connect true
Related Topic