502 Bad Gateway - nginx/1.14.0 (Ubuntu)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

502 Bad Gateway - nginx/1.14.0 (Ubuntu)

ramirezc
Recently I moved my Dell Server from one location to another, with a
completely different Router. Its Main OS/VM Manager is Proxmox VE 5.3. I got
an Nginx VM that is Reverse Proxying several other VMs.

After configuring my new Router, I got several of my VMs to connect to the
Internet (setting the same Private IPs to the same MAC Addresses, and
opening the same ports for the same Private IPs). However, with my Discourse
VM, I am receiving 502 Bad Gateway - nginx/1.14.0 (Ubuntu) when trying to
access Discourse in a Browser.

In the past, it was usually through the Discourse software that I could fix
the problem ... but not so this time. Please read here for more details:
https://meta.discourse.org/t/502-bad-gateway-nginx-1-14-0-ubuntu-unable-to-find-image-locally-error-response-from-daemon/133392

I've basically hit a point where I believe the issue is with the
configuration of the Nginx VM. Recently I've tried renewed the SSL
Certificates (using Let's Encrypt) for all my sites on Nginx, hoping it
would fix the problem ... but it didn't. However, I checked the Nginx Error
Log and found a message being reported over and over again:

> root@ngx:/etc/nginx/sites-available# less /var/log/nginx/error.log
> 2019/11/17 06:01:24 [error] 23646#23646: *37 connect() failed (111:
Connection refused) while connecting to upstream, client: 1.2.3.4, server:
discourse.domainame.com, request: "GET / HTTP/2.0", upstream:
"http://5.6.7.8:8080/", host: "discourse.domainame.com"

* 1.2.3.4 = My Old Public IP Address
* 5.6.7.8 = My New Public IP Address

It looks to me like Nginx is trying to connect this site using my Old Public
IP Address. That is definitely incorrect.
My /etc/nginx/sites-available CONF file for the Discourse Site can be found
in THIS link: https://pastebin.com/fiiyATeP

* 192.168.0.101 = Nginx VM
* 192.168.0.104 = Discourse VM

------------------------------------------------------------------------------------------------------------------------------------------------------------

So my question is: How can I tell Nginx to connect discourse.domainname.com
to my New Public IP Address 5.6.7.8?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,286226,286226#msg-286226

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: 502 Bad Gateway - nginx/1.14.0 (Ubuntu)

Francis Daly
On Sun, Nov 17, 2019 at 06:40:36AM -0500, naupe wrote:

Hi there,

> > root@ngx:/etc/nginx/sites-available# less /var/log/nginx/error.log
> > 2019/11/17 06:01:24 [error] 23646#23646: *37 connect() failed (111:
> Connection refused) while connecting to upstream, client: 1.2.3.4, server:
> discourse.domainame.com, request: "GET / HTTP/2.0", upstream:
> "http://5.6.7.8:8080/", host: "discourse.domainame.com"
>
> * 1.2.3.4 = My Old Public IP Address
> * 5.6.7.8 = My New Public IP Address

nginx is trying, and failing, to connect to 5.6.7.8:8080.

Should nginx be trying to connect to 5.6.7.8? If so, fix the network so
that it is able to connect there. If not, fix the nginx config so that
it tries to connect to the place that you want.

> My /etc/nginx/sites-available CONF file for the Discourse Site can be found
> in THIS link: https://pastebin.com/fiiyATeP

The relevant bit there seems to be

    location / {
      proxy_pass http://discourse.domainname.com:8080/;

> * 192.168.0.101 = Nginx VM
> * 192.168.0.104 = Discourse VM

When nginx starts, it will ask the system to resolve the name
discourse.domainname.com, and it (presumably) is told 5.6.7.8.

It looks to me like you want that to be 192.168.0.104 instead.

In that case - either change the system resolver; or just change the
proxy_pass line to use the 192.168.0.104 IP address instead of the
hostname.

(Other options exist too; these are probably the ones with fewest
changes.)

Good luck with it,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: 502 Bad Gateway - nginx/1.14.0 (Ubuntu)

ramirezc
Francis Day,

Wow ... that did it! You resolved my issue! After troubleshooting for 1 full
week of troubleshooting, it's resolved! Thank you so much!

So I edited my /etc/nginx/sites-available/discourse.conf file:

* I changed THIS line:
proxy_pass http://discourse.domainame.com:8080/;

To THIS line:
proxy_pass http://192.168.0.104:8080/;

So basically calling the Local IP Address instead of the Hostname as you
suggested.

Anyways, after I reloaded and restarted Nginx, and my Discourse Forum site
came right up!

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,286226,286229#msg-286229

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx