Nginx ports (8080)

Posted May 30, 2013 113.4k views
Hi, I'm configuring nginx and everything seems to work OK, except that it only "listens" to the default port (80). I'm struggling to configure it to listen to port 8080. I've tried with "listen 8080;" "listen;" "listen localhost:8080;"... but all are ignored. I made those changes in the sites-enabled file (/etc/nginx/sites-available/mysite). Do I have to change something in nginx.conf or in other file? Thanks in advance for your help!
1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
16 answers
Are you running a firewall? If you want to connect externally to it, you may have to add a rule in to iptables.
Kamal, I checked and there are some errors, but apparently all related to my CMS (Drupal), not to nginx.

Gavin, I haven't installed any firewall (at least not consciously).

Dave, I don't fully understand what you say (I'm very new to nginx and to sysadmin issues in general) but I think that could be the problem or at least related to that:
I have several domains in the same nginx server and therefore several "server declarations" in the same configuration file (all included in /etc/nginx/sites-available/mysite). When I put listen 8080; in the first server declaration (save and restart nginx) and go to that first domain, it redirects to the next domain in the nginx configuration file.

Simplifying, it's something like this:

server {
listen 8080;
server {
listen 80;

With this configuration, when I open in my browser it redirects me to That could be related to what you were talking about? That gives more clues about what could be my problem?

Thanks again for all your quick responses!
(typo: where I say "sites-enabled file" I'm referring to "sites-available file")
Try editing the listen directive so it looks like this:

listen 8080;

Also make sure the file you're editing exists in the sites-enabled directory. Don't forget to restart/reload nginx after editing the config files: service nginx restart/reload
Thanks Kamal, I was already doing all that, without luck. As I've said, it works when I put:
listen 80; (it also works when I erase the listen line, because 80 is default)
But it doesn't work when I put:
listen 8080; (or listen; or listen localhost:8080;)
Any ideas?

Make sure you have 8080, restart nginx and check the error logs.
Do you see any errors?
The first virtual block you set up is a catch all. The succeeding blocks respond to their server_name directive. Make sure that you're placing it under a valid server block. A specific server block responds only to the EXACT server_name directive that you specify. All others which do not match any server block go to the first one. Also, check your firewall.
@delvallelajas You have to create a default fallback virtualhost that nginx should serve if it gets a request for a Host/domain name it doesn't recognize.
Thanks again Kamal, but I would really appreciate if you could elaborate it a bit more (specific code of what do I have to add would be wonderful), because I don't know enough to translate your advice to code.

I've googled "default fallback virtualhost nginx" and reached to and, but I don't know if that is what you are talking about and I don't know how to apply it to my case anyway.

I've tried adding a code included in that first link (talking about "catch-all servers"):
server {
listen 80 default_server;
server_name _;
return 444;

When I add this, I get Error 324 (net::ERR_EMPTY_RESPONSE):
@delvallelajas The virtualhost block you added is correct. You just have to replace "return 444;" with "root /var/www/default/public_html" where /var/www/default/public_html is the path to the directory that holds the files that should be served in case nginx receives a request for a domain name it can't recognize.
Previous 1 2 Next