NGINX default site works, but one on another port does not NGINX default site works, but one on another port does not nginx nginx

NGINX default site works, but one on another port does not


you must to be allow your 8080 port in firewall

If you're not installed ufw install it like

$ sudo apt install ufw

Then check the ufw status

$ sudo ufw status

Check your needed port is added into the list.

then use

 $ sudo ufw allow 8080 

then check the ufw status again. now it show you the allowed ipv4, ipv6 ports and connections. Restart your nginx server and check the port is working

$ sudo systemctl nginx restart$ curl -I 'http://{youraddress}:8080'

Or hit the url in your browser.

If you are using GCP, AWS check the external firewall settings in your server console. like http_server allow 80. and edit this record to 80, 8080 and save it.

Caution: Don't do the internal firewall settings using ufw in GCP, AWS because already they have their own firewall settings for the engines.

Thank you


Your configuration are correct. I maybe add "server_name" to each server.

You should add logging to each virtual host, adding this to each server {} entry:

access_log  /var/log/nginx/server.intra-upstream.log upstream buffer=16k;access_log  /var/log/nginx/server.intra-access.log combined buffer=16k;

You also need to add to your http {} entry to make upstream log works:

log_format upstream '$remote_addr - $remote_user [$time_local]  $request '                    '$upstream_addr $upstream_cache_status $upstream_status $upstream_response_time';

You can check the requests logs at those files. Upstream log the transaction with PHP-FPM and access the HTTP request.

You could have some iptables block or other network limitation.

To check if your server are listening at port 8080, use this command as root:

bash# netstat -nap | grep -i nginx

This will show you something like this:

tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      939/nginx: master ptcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      939/nginx: master ptcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN      939/nginx: master ptcp        0      0 0.0.0.0:82              0.0.0.0:*               LISTEN      939/nginx: master punix  3      [ ]         STREAM     CONNECTED     17513    939/nginx: master punix  3      [ ]         STREAM     CONNECTED     17512    939/nginx: master punix  3      [ ]         STREAM     CONNECTED     17518    939/nginx: master punix  3      [ ]         STREAM     CONNECTED     17519    939/nginx: master p

In my case, NGiNX are listening at port 80, 81, 82 and 443.

To check you iptables rules, type:

bash# iptables-save

I'll not put here the output because it may vary a lot, and you just need to check the default INPUT rule (at top of output), like this:

*filter:INPUT DROP [67342:4090666]

In my case, INPUT are default DROP. If you see an ACCEPT there, it's ok, otherwise you need to check if there's any explicit rule accepting packets at the port 8080.

If you've INPUT as DROP, you can test if this are your problem opening port 8080 with this command:

bash# iptables -A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT


I have tested your configuration, and it seems correct to me. Some things that comes to my mind that could cause the unexpected behavior you are experiencing:

  • As others have said, did you restart nginx after creating the last conf file? I know it does sound silly but i forgot to do that myself a lot of time.
  • Permission issues or wrong path for the root domain directive. Are you sure the www.domain2.com files directory exists and/or is readable by www-data / your nginx user?
  • Check your DNS. Did you remember to add the www.domain2.com and other domain to your hosts file (assuming you are working on your own box, of course)? Are your domains reachable via ping or telnet?
  • Try to validate your sintax, sudo nginx -t. Does it say something interesting?