Nginx ports (8080)

  • Posted May 30, 2013

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!


do it in /etc/nginx/conf.d/your_domain.conf

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Kamal, I checked and there are some errors, but apparently all related to my CMS (Drupal), not to nginx. <br> <br>Gavin, I haven’t installed any firewall (at least not consciously). <br> <br>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: <br>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. <br> <br>Simplifying, it’s something like this: <br> <br>server { <br> listen 8080; <br> server_name; <br> … <br>} <br>server { <br> listen 80; <br> server_name; <br> … <br>} <br> <br>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? <br> <br>Thanks again for all your quick responses!

Are you running a firewall? If you want to connect externally to it, you may have to add a rule in to iptables.

Folks, this is a banana slip ! the conf file is being generated dynamically and actually does not point to /etc/nginx/available-sites/default !!! Take a look at ps -ef | grep nginx and you will see the actual conf file !!!

Hi kamaln7. I config Nginx run on port 80 and httpd run on port 8080. But when i test my code on local only apache installed, it’s ok. But when I up code on server, It auto add 8088 to all my link href, hix hixx. This make terible my system. It have error :(.

What would you like to happen when someone vists on port 80?

It says the following (I edited the paths and domains for security/privacy): <br> <br>2013/06/02 13:22:48 [error] 9861#0: *6 directory index of “/home/path/whatever/” is forbidden, client:, server: _, request: “GET / HTTP/1.1”, host: “” <br>2013/06/02 13:22:49 [error] 9861#0: *6 open() “/home/path/whatever/favicon.ico” failed (2: No such file or directory), client:, server: _, request: “GET /favicon.ico HTTP/1.1”, host: “” <br> <br>I thought that was the correct path, but maybe that’s the problem. You talked about “/var/www/default/public_html”, but I don’t have a that directory (there is no “www” in “var”). <br>My files are in “/home/path/whatever/domain1”, “/home/path/whatever/domain2”… so I guess “/home/path/whatever/” is the “directory that holds the files that should be served in case nginx receives a request for a domain name it can’t recognize”. Please correct me if I didn’t understood it correctly. <br> <br>Maybe it’s also relevant to mention that I’m using Drupal and my nginx config is the one described in this page: (it’s the first result that appears when you search “drupal nginx” in google, so I guess it’s a standard and well tested config) <br> <br>

@delvallelajas keep the configuration you posted first, restart nginx, reload your browser, and check the error files in /var/log/nginx. Paste the last few lines, the cause of the 403 Forbidden error should be there.

Well, probably I’m doing something wrong, because it doesn’t work either. <br> <br>If I put something like the following config, I get 403 forbidden: <br> <br>server { <br>listen 80 default_server; <br>server_name _; <br>root /var/www/default/public_html; (changing that to my appropriate directory) <br>} <br>server { <br>listen 8080; <br>server_name; <br>… <br>} <br>server { <br>listen 80; <br>server_name; <br>… <br>}
<br> <br>And if i put something like the following config (listen 8080 instead of listen 80 in default_server), it happens the same as before without the default_server code (it redirects from domain1 to domain2): <br> <br>server { <br>listen 8080 default_server; <br>server_name _; <br>root /var/www/default/public_html; (changing that to my appropriate directory) <br>} <br>server { <br>listen 8080; <br>server_name; <br>… <br>} <br>server { <br>listen 80; <br>server_name; <br>… <br>}
<br> <br>This is not indispensable for my project right now, so guess I’m going to give up on this. It seems too difficult for somebody with my almost inexistent knowledge of nginx. Thanks anyway for all your help.

@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.

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. <br> <br>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. <br> <br>I’ve tried adding a code included in that first link (talking about “catch-all servers”): <br>server { <br> listen 80 default_server; <br> server_name _; <br> return 444; <br>} <br> <br>When I add this, I get Error 324 (net::ERR_EMPTY_RESPONSE):