nginx starting but isn't listening on port 80
In the process of writing the question and reproducing the steps I figured out what the problem was.
I had created and edited my sites-available server in /etc/nginx/sites-available/mysite.tld
Then to enable the site, I was in the directory /etc/nginx/
when in my tired state created the link into the sites-enabled folder by running ln -s sites-available/mysite.tld sites-enabled/mysite.tld
.
It wasn't until this morning that I realized I had created a bad link when I couldn't vim into the sites-enabled linked version.
Doing an rm
on the bad link and then using absolute paths for the whole thing ln -s /etc/nginx/sites-available/mysite.tld /etc/nginx/sites-enabled/mysite.tld
then a subsequent restart of nginx now shows it listening on port 80 as expected.
tl-dr; sometimes it's best to just go to bed and look at it in the morning
nginx doesn't listen on port 80 twice?
When you specify default_server
flag on a listen
directive, nginx will use that server
block to serve any request where HTTP Host
header does not match the server_name
in any other server blocks (or the request missing Host
header at all). You can use default_server
flag on any particular IP:port combination given as parameter of listen
directive only once. But you can use this flag several times on different IP:port combinations.
Some examples, assuming your server have several network interfaces:
server {
listen 1.2.3.4:80 default_server; # this will be default server block for any request coming to 1.2.3.4 IP address on port 80
...
}
server {
listen 5.6.7.8:80 default_server; # this will be default server block for any request coming to 5.6.7.8 IP address on port 80
...
}
server {
listen 80 default_server; # this will be default server block for any request coming to any other IP address (except 1.2.3.4 and 5.6.7.8) on port 80
...
}
Working example:
Typically, when I need to serve several sites on the same server, I use the following configuration (of course this is simplified, nowadays we typically use HTTPS with http://example.com
to https://example.com
redirection):
Site 1 config file
server {
listen 80;
server_name example1.com www.example1.com;
...
}
Site 2 config file
server {
listen 80;
server_name example2.com www.example2.com;
...
}
Default server config file
server {
listen 80 default_server;
server_name _;
return 444;
}
Because of default_server
flag on listen
directive third server block is used when the request's Host
header doesn't contain one of my sites names (or the request does not have Host
header at all). I don't expect visitors that doesn't know what site they are visiting (these are typically port scanners, vulnerability searchers etc.), so I use special nginx 444 code (close connection without any response) for them.
Nginx is listening on port 80 or 443 but not responding
It turns out that the DNS configuration went mad and pointed my domain to somewhere else. I fixed the DNS so the site will come back soon.
thanks
Related Topics
How to Record What Process or Kernel Activity Is Using the Disk in Gnu/Linux
Getting List of Network Devices Inside the Linux Kernel
Sending Keyboard Input to a Program from Command-Line
Help with Understanding a Very Basic Main() Disassembly in Gdb
Bash Alias with Argument and Autocompletion
How to Add Date String to Each Line of a Continuously Written Log File
Upstart Calling Script (For Inserted Usb-Drive)
Difference Between Flat Memory Model and Protected Memory Model
Windows Authentication Headers Without .Net. Possible
Extract Tar the Tar.Bz2 File Error
How to Reinstall the Latest Cmake Version
Error: Service "Xxx" Uses an Undefined Network "Xxx"
Using Linux How to Pass the Contents of a File as a Parameter to an Executable
How to Install Packages from Command Line on Suse
How to Cut First Column (Variable Length) of a String in Shell