nginx not listening to port 80
Asked Answered
E

12

81

I've just installed a Ubuntu 12.04 server and nginx 1.2.7, removed default from sites-enabled and added my own file into sites-available and symlink at sites-enabled. Then restarted nginx.

Problem: However going to the URL does not load the site. netstat -nlp | grep nginx and netstat -nlp | grep 80 both returns no results! lsof -i :80 also returns nothing. A dig from another server returns the correct ip address so it shouldn't be a DNS problem. I was able to connect to apache which I have now stopped its service. nginx logs also show nothing.

How should I troubleshoot this problem?

/etc/nginx/site-available/mysite.com

server {
    listen   80;
    server_name www.mysite.com mysite.com *.mysite.com;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    root /var/www/mysite/public;

    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args ;
    }
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_read_timeout 300;
    }

}
Ernaernald answered 15/4, 2013 at 17:45 Comment(7)
anything in the logs?Ridenhour
Is it actually running? Did you start it with sudo?Cleavage
Please don't downvote a question just because you don't know the answer. I'm having the same issue. Nothing in access logs... it's listening on *:80. No error in the debug error log. And yes, @DondiMichaelStroma it is running. (lol).Enloe
did you find out what the problem was? I'm having similar issue...Bambara
I was using centos-6. it doesn't have site-enabled etc. I have to remove server entry /etc/nginx/conf.d/default.conf and add nginx.conf in same directory.Gentes
same issue for port 80, but nginx listen on other port is working...can anyone helpPeremptory
Helped me as well. I was being sloppy about my linking and server blocks thanks @ErnaernaldNeutral
M
141

I had this same problem, the solution was that I had not symlinked my siteconf file correctly. Try running vim /etc/nginx/sites-enabled/mysite.com—can you get to it? I was getting "Permission Denied."

If not run:

rm /etc/nginx/sites-enabled/mysite.com
ln -s /etc/nginx/sites-available/mysite.com /etc/nginx/sites-enabled/mysite.com
Mammoth answered 29/9, 2013 at 23:21 Comment(12)
This fixed it for me! Apparently when you don't type in the full filename in the second argument, i.e. ln -s /etc/nginx/sites-available/mysite.com /etc/nginx/sites-enabled/, it creates sort of a fake symlink, which nginx chokes on. Strange, but true.Sweeten
This was the solution for me too. Stumbled upon this thread while googling for answers.Pirog
This was also a solution for me. I have been running in circles for hours trying to fix an nginx install. Bravo, ye gentleman!Alodi
Thanks guys! I realized I had done something similar when creating a symlink earlier today. Recreated it with the full path and bingo, nginx loaded the config for my new site.Deadlight
Thank you thank you. I was pulling my hair out for the last 2 hours!!Lagas
Thank you thank you! Been banging my head against the keyboard for hours trying to troubleshoot.Starla
Thank you for this, it was driving crazy. The tutorial I was following actually had a relative symlink.Lavernelaverock
1 mistake, 9 hoursRickrickard
Damn this was extremely aggravating! THANK YOU!Serotherapy
Yep, same issue and same solution! Remember to reload the nginx config after the change. sudo service nginx reloadSchlieren
THIS was literally what brought back my production site - so thank you!!Airborne
This also saved my ass. Just saying.Attenuant
E
38

If your logs are silent on the issue, you may not be including the sites-enabled directory. One simple way to tell that the site is being loaded is to set the error/access log path within your server block to a unique path, reload nginx, and check if the files are created.

Ensure the following include directive exists within the http context in /etc/nginx/nginx.conf.

http {
  ...
  include /etc/nginx/sites-enabled/*;
}
Elaterite answered 25/9, 2013 at 1:40 Comment(3)
Such a simple thing to miss. Thank you for mentioning it!Beamer
Thanks a lot! You save my daySaracen
In some versions of nginx you have to write include /etc/nginx/sites-enabled/*.*;Matrimony
S
13

I've found it helpful to approach debugging nginx with the following steps:

1... Make sure nginx is running.

ps aux | grep nginx

2... Check for processes already bound to the port in question.

lsof -n -i:80

3... Make sure nginx has been reloaded.

sudo nginx -t
sudo nginx -s reload

On Mac, brew services restart nginx is not sufficient to reload nginx.

4... Try creating simple responses manually to make sure your location path isn't messed up. This is especially helpful when problems arise while using proxy_pass to forward requests to other running apps.

location / {
    add_header Content-Type text/html;
    return 200 'Here I am!';
}
Supraorbital answered 4/11, 2018 at 4:11 Comment(2)
I tried using lsof -nP to check if nginx was listening. Only nginx does not show up in lsof, only in netstat -van. Maybe it's because nginx does not open sockets like a file but using special async io calls?Exothermic
brew services * nginx works when I prefix sudo .... See also #38041232Exothermic
C
7

I ran into the same problem, I got a Failed to load resource: net::ERR_CONNECTION_REFUSED error when connecting over HTTP, but fine over HTTPS. Ran netstat -tulpn and saw nginx not binding to port 80 for IPv4. Done everything described here. Turned out to be something very stupid:

Make sure the sites-available file with the default_server is actually enabled.

Hope this saved some other poor idiot out there some time.

Cancellate answered 3/2, 2015 at 14:59 Comment(0)
D
5

You are probably binding nginx to port 80 twice. Is that your full config file? Don't you have another statement listening to port 80?

Dittany answered 16/8, 2013 at 17:10 Comment(4)
I was trying to host GitLab on port 80 but found out there was also a "default" site bound to that port. After removing the latter my GitLab host was running fine.Aubry
@Aubry removing that site's configuration should work, but you can also use different server_names in case you want to listen to port 80 multiple timesDittany
@Dittany - Upvoted your comment , thanks this was helpful.Cant
nginx has a default site in /etc/nginx/sites-enabled, I removed it and now it works!Aiaia
R
3

A semi-colon ; missing in /etc/nginx/nginx.conf for exemple on the line before include /etc/nginx/servers-enabled/*; can just bypass this intruction and nginx -t check will be successful anyway.

So just check that all instructions in /etc/nginx/nginx.conf are ended with a semi-colon ;.

Rustler answered 27/12, 2016 at 20:52 Comment(0)
M
3

I had faced the same problem over the server, here I am listing the how I had solved it :

Step 1 :: Installing the Ngnix

sudo apt update
sudo apt install nginx

Step 2 – Adjusting the Firewall

sudo ufw app list

You should get a listing of the application profiles:

Output Available applications: Nginx Full Nginx HTTP Nginx HTTPS OpenSSH

As you can see, there are three profiles available for Nginx:

Nginx Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)

Nginx HTTP: This profile opens only port 80 (normal, unencrypted web traffic)

Nginx HTTPS: This profile opens only port 443 (TLS/SSL encrypted traffic)

Since I haven’t configured SSL for our server yet in this guide, we will only need to allow traffic on port 80.You can enable this by typing:

sudo ufw allow 'Nginx HTTP'

You can verify the change by typing:

sudo ufw status

Step 3 – Checking your Web Server

systemctl status nginx

Now Check port 80 , It worked for me hope will work for you as well.

Mechellemechlin answered 27/1, 2020 at 13:49 Comment(1)
#74912691 I am having this issue, can you help me explainCud
P
1

Have you checked if your nginx binary really exists? please check if

#whereis nginx

outputs the binary path and check this path with your init script from /etc/init.d/nginx. e.g.

DAEMON=/usr/sbin/nginx

(In my init script "test -x $DAEMON || exit 0" is invoked and in any case this script returned nothing - my binary was completely missing)

Paschall answered 22/8, 2013 at 14:58 Comment(0)
I
1

While we all think we don't make silly mistakes, we do.

So, if you are looking into NGINX issues and all signs are showing it should work then you should take a step away from the files and look downstream.

System Firewall, Hardware Firewall, Nat router/firewall.

For myself this issue was my router, I run a home lab and so I can access services behind my router from afar I use NGINX to reverse proxy as my router only handles incoming based on IP and doesn't do any handling of hostnames, I'm sure this is all fairly normal.

In any case my issue cropped up as I was securing my network a few days ago, removing some port forwarding that isnt needed any longer and I accidentally removed port 80.

Yes it was as simple as forwarding that port again to NGINX and all was fixed.

I will now walk away with my head hung in extreme shame though I leave this answer to show my gratitude to the people in this thread that lead me to find my own error.

So thank you.

Impious answered 9/10, 2019 at 21:41 Comment(0)
T
0

In my case those network command's outputs showed nginx was correctly binding to port 80, yet the ports weren't externally accessible or visible with nmap.

While I suspected a firewall, it turns out that old iptables rules on the machine were redirecting traffic from those ports and conflicting with nginx. Use sudo iptables-save to view all currently applicable rules.

Tripartition answered 5/4, 2019 at 8:1 Comment(0)
S
0

If Nginx is set up correctly and running well (you can check it with systemctl status nginx ), I believe it would be a firewall issue. Double check you have opened the port 80 with sudo ufw status, if not you can open your port with sudo ufw allow 80/tcp . Check also on your server provider. While it may have worked in the past, it may have been from a whitelisted IP address and not work now from another address.

Finally, it may be a permission issue. Make sure you grant permissions to the folder where your website files are with: sudo chmod -R 755 /var/www/mysite/public

If that still doesn’t work, I have written a whole step-by-step guide on setting up a website with Nginx at: https://medium.com/p/46f34afc15df

Sanyu answered 23/4 at 12:51 Comment(0)
S
-1

I am facing the same issue. Just reload the nginx help me

sudo nginx -t

If you got error then just delete the log.txt file then,

sudo nginx -s reload
Sort answered 11/9, 2021 at 7:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.