Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

"502 Bad Gatway" error after in nginx after reverse proxy of https to http

I have a web server running on 8030 port and some static web files which should be accessed through 80 port. Both front-end and back-end files are on same linux machine.

The front-end receives data from back-end using REST API. I have a static IP and a domain name. DNS server is a CDN which connects https://a.b.com to my IP address, i.e. 1.2.3.4 here. My server itself has no SSL certifications.

So my front-end app is hosted on https://a.b.com and makes GET requests to http://1.2.3.4:8030/v1/getdata

This is my NGINX configuration file:

upstream backend {
        server 1.2.3.4:8030;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /home/user/static;

        index index.html;

        server_name https://a.b.com;

        location / {
               
                try_files $uri$args $uri$args/ /index.html;
        }

        location /v1 {
                proxy_pass http://backend;

        }
}

Static files are loaded successfully but the AJAX GET request to my application server returns "502 Bad Gateway".

How can I fix this?

Firewall rules are set and remote access using static IP is OK.

question from:https://stackoverflow.com/questions/65884750/502-bad-gatway-error-after-in-nginx-after-reverse-proxy-of-https-to-http

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I changed the config file as following and now everything is OK:

upstream backend {
        server localhost:8030;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        index index.html;

        server_name _;

        location / {

                root /home/user/output;

                try_files $uri$args $uri$args/ /index.html;
        }

        location /v1 {
                proxy_pass http://backend;
        }

}

Thanks to this


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...