Nginx/0.8.54 - 502 Bad Gateway

Hi,

I’m running nginx as a reverse proxy for a jetty. I host a Liftweb App
on localhost:8080. Nginx is listening on Port 81.

Here is my nginx.conf:

server {
listen 81;
server_name mysite.com www.mysite.com;

            location / {
                    proxy_pass http://127.0.0.1:8080;
                    proxy_set_header  X-Real-IP  $remote_addr;
                    proxy_read_timeout 700;
                    proxy_set_header Host $http_host;
                    proxy_set_header X-Forwarded-For

$proxy_add_x_forwarded_for;
}
}

When I try to point my browser to mysite.com:81 I always get a 502 Bad
Gateway message. I checked the log and found this:

connect() failed (111: Connection refused) while connecting to upstream,
client: 12.34.567.890, server: mysite.com, request: “GET /favicon.ico
HTTP/1.1”, upstream: “http://127.0.0.1:8080/favicon.ico”, host:
mysite.com:81

Does this means this port is blocked? I tried other but the result is
still the same…

My hosting company gave me the advice better not to use port 80 (i’m in
china) and use some socket instead. I don’t know what they mean by that.
I use port 81 for nginx now. Anyone an idea what they could mean by “use
sockets”? I read somewhere that i can later forward all traffic from 81
to port 80.

Any hints a very much appreciated.
Thanks.

Posted at Nginx Forum:

On 20 Jul 2011 14h43 WEST, [email protected] wrote:

When I try to point my browser to mysite.com:81 I always get a 502
Bad Gateway message. I checked the log and found this:

There’s a problem in your upstream. Its refusing the connection? Do
you have some sort of access controls on it?

Try:

curl -I http://localhost:8080 and see if you can connect.

connect() failed (111: Connection refused) while connecting to
upstream, client: 12.34.567.890, server: mysite.com, request: “GET
/favicon.ico HTTP/1.1”, upstream:
http://127.0.0.1:8080/favicon.ico”, host: “mysite.com:81

Does this means this port is blocked? I tried other but the result
is still the same…

My hosting company gave me the advice better not to use port 80 (i’m
in china) and use some socket instead. I don’t know what they mean
by that. I use port 81 for nginx now. Anyone an idea what they
could mean by “use sockets”? I read somewhere that i can later
forward all traffic from 81 to port 80.

If you want it to work transparently use port 80 for your frontend.

— appa

Access control? Not that I know of. I didn’t touch the firewall yet, so
I guess there is none enable right now.

curl -I http://localhost:8080 and see if you can connect.

I did this on the server and I got:
curl -I http://localhost:8080
curl: (7) couldn’t connect to host

And I tried from a remote client to connect via curl and got:

curl -I http://myside.com:81
HTTP/1.1 502 Bad Gateway
Server: nginx/0.8.54
Date: Wed, 20 Jul 2011 16:14:04 GMT
Content-Type: text/html
Content-Length: 172
Connection: keep-alive

Any clue?

Posted at Nginx Forum:

curl -I http://localhost:8080 and see if you can connect.

I did this on the server and I got:
curl -I http://localhost:8080
curl: (7) couldn’t connect to host

Your backend / application isn’t working that’s why nginx can’t connect
to it and has to return 502.

rr

Er, wrong email. Sorry!

all set, my fault.

Hello,

First replace
proxy_pass http://127.0.0.1:8080;
by
proxy_pass http://monsite.com:8080;

If that doesn’t work, look at firewall settings, yes. Port 8080 on the
upstream must be accessible from the machine running nginx (even if
they are the same physical machine).

A.

Your backend / application isn’t working that’s why nginx can’t
connect to it and has to return 502.

The app is up and running on port 8080. I can access the app directly
using mysite.com:8080. Do I have to configure something else, maybe the
firewall?

Posted at Nginx Forum:

Did you try to just have your nginx listen on port 80 and see if it
works ?

A.

First replace
proxy_pass http://127.0.0.1:8080;
by
proxy_pass http://monsite.com:8080;

Gee, so simple! Yes, that worked. Thank you very much!! To finish
everything I need to forward port 81 to port 80. I guess a firewall rule
will help me out here.

Posted at Nginx Forum:

Did you try to just have your nginx listen on port 80 and see if it
works ?

Yes, I did. It is not working. I need to whitelist my IP and for that I
have to do some more paperwork. I’m in China. But my Chinese hosting
company said I should use Socket (Socks?), but I don’t know what they
mean by that. My solution was to use another port (like port 81) and
forward the traffic then. Any other solutions possible?

Posted at Nginx Forum:

I have no clue what they mean when they say you should use Socks. If
they don’t let TCP traffic go to port 80 on your machine, there is
nothing you can do but publish your URLs as http://monsite.com:81/

Of course, you could also do the paperwork.

A.