I'm now going to deploy my node.js app on Google Compute Engine via nginx, but after all the configurations are done, I hit the wall with "502 Bad Gateway" error.
Then, after digging out for so many hours, I finally found that the proxy_pass
field in /etc/nginx/sites-available/server.conf
should be your actual internal IP address displayed in GCE's console, instead of http://127.0.0.1
. The conf file is the following (some values are just for the illustration purposes only):
server {
listen 80;
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl/example.crt;
ssl_certificate_key /etc/nginx/ssl/example.key;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://10.102.24.152:8888;
}
}
However, all the tutorials I followed set the value at proxy_pass
to http://127.0.0.1
. But in my case it didn't work at all. The example of the tutorials are as follows:
- https://github.com/ShoppinPal/gcp-scripts/wiki/Setup-Nginx-on-Google-Cloud
- http://support.ghost.org/setup-ssl-self-hosted-ghost/
- https://www.digitalocean.com/community/questions/problem-with-ssl-and-ghost
So I now wonder if it is the correct way to make the server working. Or does this lead to something prone to be valnurable in security? Or maybe 127.0.0.1
is the correct figure and there are other problems on my side?