简体   繁体   中英

502 Bad Gateway node server nginx

i built react app which is running on node server, i'm using multiple submain in same gcloud instance.using pm2 i'm running those app which works fine on different ports.
right now i want to implement nginx on my vm so i can target those apps with specif domain. my servers.conf (nginx file)

server {
        listen 80;
        listen [::]:80;
        server_name booking.stanplus.com www.booking.stanplus.com;
        return 301  https://booking.stanplus.com$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name booking.stanplus.com  www.booking.stanplus.com;
    ssl_certificate /etc/letsencrypt/live/booking.stanplus.com/cert.pem;
    ssl_certificate_key /etc/letsencrypt/live/booking.stanplus.com/privkey.pem;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass https://35.237.131.149:8080;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
server {
        listen 80;
        listen [::]:80;
        server_name dkiosk.stanplus.com;
        location / {
                proxy_pass http://127.0.0.1:3000;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header HOST $http_host;
        }
}

http://dkiosk.stanplus.com working fine but https://booking.stanplus.com/ got ssl but not working.
https://booking.stanplus.com/ is targeting on http://35.237.131.149:8080/ which is working fine. https://booking.stanplus.com/ giving me error

502 Bad Gateway

where i'm doing wrong...?,first time i'm implementing nginx.
i looked lot of articles and Q&S but get confessed. plz help me.i'm stuck since 3days.

In your configuration you use:

proxy_pass http s ://35.237.131.149:8080;

That is, you request nginx to use HTTPS - an encrypted connection to the backend. Most likely this is wrong, given that port 8080 in most cases is used for plain HTTP (without S). And the URL you claim working, http://35.237.131.149:8080/ , is also plain HTTP, not HTTPS.

Changing proxy_pass argument to http://35.237.131.149:8080/ should resolve your problem.

Note well that nginx generally logs error details to the error log. If in doubt, don't hesitate to look into it, in many cases it has enough information to understand what is going wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM