I am using Nginx web server and getting error “502 bad gateway” while
accessing some sites.
I have observed that, proxy_pass port is not listing in the server.
e.g.:- In above configuration example.com is running on port 80 and
proxy_pass localhost is running on port 8009.
Port 80 is listing perfectly but port 8009 is not listing because of
this
reason example.com is not working. Please suggest me on this.
Your configuration means that Nginx is listening on port 80 and will
forward any request form example.com to a backend located on localhost
listening on port 8009.
Since Nginx is a proxy, you need a backend to serve content to which
requests sent to Nginx will be forwarded.
You seem not to understand what you are doing…
You machine is doing precisely what you ask it to do. Not more, not
less.
the port in proxy_pass is not for listening/accepting incoming
connections - it is for connecting outwards to another server/service
You must have something else (another httpd, probably not nginx)
listening on 8009…?
You can’t browse to the URL because there is no web application running
on port 8009.
You tell nginx to listen on port 80…so far all good.
But then you are telling nginx to proxy_pass the request to a diferent
port…
So the question is more: is this really what you want? If so… may I
ask what’s supposed to be listening on port 8009?
I mean you said before that nothing is listening on port 8009… but you
want nginx to proxy the requests to that port… this makes no sense.
Thanks for the reply. I have never worked on Nginx server. So please help me
to resolve the issue.
You’ve been told what the problem is 3 times already. It’s nothing to
do with nginx. The problem is that the process that nginx has been
configured totalkto on port 8009 is not listening on port 8009.
Fix that.
The log tells you much… although has was already said the problem is
that something’s wrong with whatever should be listening on those
ports…
Openerp is one of those and probably is not running or at least it’s not
listening on the port specified in nginx configuration…
In any case the problem is not in nginx… find out what is supposed to
be listening on those ports… I doubt you will have problems with nginx
after that.
“502 Bad Gateway” almost always means something is wrong with the
upstream server (i.e., Nginx is working fine, whatever it’s proxying to
is having problems) so look for a problem there.
Note that the log entries from your previous email indicate upstream
servers on ports 8002 and 8007. According to what you’ve posted here,
there’s nothing listening on either of those ports.
I have scanned the listing ports in the servers. Please help me out to
fix
this issue.
I never worked on Nginx server and am totally stuck.
sudo nmap localhost
Starting Nmap 5.21 ( http://nmap.org ) at 2013-07-23 20:15 EDT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000018s latency).
Not shown: 991 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
80/tcp open http
631/tcp open ipp
5432/tcp open postgresql
5666/tcp open nrpe
8008/tcp open http
8009/tcp open ajp13
8090/tcp open unknown
Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds
sudo nmap IP_Address
Starting Nmap 5.21 ( http://nmap.org ) at 2013-07-23 20:15 EDT
Nmap scan report for hostname (IP_Address)
Host is up (0.000019s latency).
Not shown: 992 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
80/tcp open http
5666/tcp open nrpe
8008/tcp open http
8009/tcp open ajp13
8080/tcp open http-proxy
8090/tcp open unknown
Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds
If 8009 is the desired port, then change the upstream server in your
nginx conf to use port 8009. If 8002/8007 are the correct ports, then
change the upstream server to listen on those ports.
Are there supposed to be services running on ports 8002 and 8007? If so,
then they don’t seem to actually be running and you need to fix that
(that’s not nginx-related). If you actually meant to proxy to another
port(s), then look at your nginx config, find where you’re proxying to
8002 and 8007 and change those to the correct ports.
I have observed that, Nginx configured on port 80 as per
/etc/nginx/sites-enabled/default file but it is listening on port 8080
and
80. Please see the details for the same.
tcp 0 0 Public_IP:8080 0.0.0.0:* LISTEN
18674/nginx off (0.00/0/0)
Port 80 is listening on 0.0.0.0
sudo netstat -anop | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:*
LISTEN
18674/nginx off (0.00/0/0)
When I am trying to start the nginx service without init.d script
getting
below message.
#sudo /usr/sbin/nginx
[sudo] password for xyz:
nginx: [warn] conflicting server name " example.com " on 0.0.0.0:80,
ignored
nginx: [warn] conflicting server name " example1.com " on 0.0.0.0:80,
ignored
nginx: [warn] conflicting server name "example.com " on 0.0.0.0:80,
ignored
nginx: [warn] conflicting server name "example2.com " on 0.0.0.0:80,
ignored
nginx: [emerg] bind() to Public_IP:8080 failed (98: Address already in
use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to Public_IP:8080 failed (98: Address already in
use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to Public_IP:8080 failed (98: Address already in
use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to Public_IP:8080 failed (98: Address already in
use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to Public_IP:8080 failed (98: Address already in
use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
Go back over all your nginx conf files, making sure to look at included
files as well… it seems that somewhere you have “listen 8080” and
possibly overlapping “server_name” directives.
If that fails, I’d suggest you backup then throw out your current
config, then start simple and build it up one piece at a time, testing
each addition. E.g., start with just a single “server” block, get it
working, then add the next one, etc. etc.
Yes you are correct. I have tried to change the port from 8080 to 80 in
/etc/nginx/conf.d/default.conf.
Browse the Public IP address and xyz.com site, getting “no handler
found”
error.
File /etc/nginx/conf.d/default.conf content as follows.