How to resolve Nginx “proxy_pass 502 Bad Gateway” error

别来无恙 提交于 2019-12-23 09:56:11

问题


I have trying to add proxy_set_header in my nginx.conf file. When I try to add proxy_pass and invoke the URL it throws 502 Bad Gateway nginx/1.11.1 error.

Not sure how to resolve this error:

upstream app-server {
    # connect to this socket
    server unix:///tmp/alpasso-wsgi.sock;    # for a file socket
}

server {
    server_name <name>;

    listen 80 default_server;

    # Redirect http to https
    rewrite ^(.*) https://$host$1 permanent;
}

server {
    server_name <name>;

    listen 443 ssl default_server;

    recursive_error_pages on;

    location /azure{
        proxy_pass http://app-server;
    }

    ssl on;
    ssl_certificate      /etc/nginx/server.crt;
    ssl_certificate_key  /etc/nginx/server.key;
    ssl_client_certificate /etc/nginx/server.crt;
    ssl_verify_client optional;
}

回答1:


Had similar problem with proxy_pass, if your Linux server is using SELINUX then you may want to try this.

setsebool -P httpd_can_network_connect true

Refer to Warren's answer: https://unix.stackexchange.com/questions/196907/proxy-nginx-shows-a-bad-gateway-error




回答2:


Try:

location /azure {
    proxy_pass appserver;
}



回答3:


502 is sent when your upstream is not reachable.

Try to switch on error log and you might see failed to connect to upstream, for this you need to check whether your upstream server is running or not, sudo service upstream status, and try to switch that on.



来源:https://stackoverflow.com/questions/39183357/how-to-resolve-nginx-proxy-pass-502-bad-gateway-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!