I am running a LEMP stack that was serving requests from both local and remote IP addresses, and now it's not serving requests at all. I was trying to set up virtual hosts on it when it stopped serving remote requests. I tried to fix this and now it's not serving local requests either. Whenever I try to access the website, from the LAN or the Internet, I get an error message that says (in Chrome): "This site can't be reached... ERR_CONNECTION_REFUSED"

I can ping the server's internal IP address, external IP address, and domain name, but I can't get the website to load. I'm also working on it via SSH, not directly on the machine. This is a configuration issue, not a networking issue.

Here is my website's config file: /etc/nginx/sites-available/anneliesephotos.com

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /usr/share/nginx/ftp/lauren/anneliesephotos;

    index index.php index.html index.htm index.nginx-debian.html;

    server_name anneliesephotos.com;
    # www.anneliesephotos.com;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        #try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php?q=$uri$args;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        # With php-cgi (or other tcp sockets):

    location ~ /\.ht {
            deny all;

Here's what my /etc/nginx/sites-available/default file has:

server {
    listen 80;
    listen [::]:80;
    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            #try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php$is_args$args;
    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
            expires max;
            log_not_found off;

When I look at the default file in Nano, the lines "expire max;", "log_not_found off;", and the closing curly brace on the next line after them have solid red blocks to the left of them, almost like an error.

This is what the /etc/nginx/nginx.conf file looks like:

user www-data;
worker_processes 2;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    multi_accept on;

http {

    # Basic Settings

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    server_tokens off;

    #server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # SSL Settings

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Gzip Settings

    gzip on;
    gzip_disable "msie_6";
    gzip_min_length 1100;

    gzip_vary on;
    gzip_proxied any;
    # gzip_comp_level 6;
    gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml
    application/x-font-ttf font/opentype application/vnd.ms-fontobject;

    # Virtual Host Configs

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*.*;

/etc/nginx/sites-enabled has a symbolic link to the /etc/nginx/sites-available/anneliesephotos folder

lrwxrwxrwx 1 root root   42 Nov 24 02:44 anneliesephotos -> /etc/nginx/sites-available/anneliesephotos

When I run netstat -tlpn, I see that for some reason port 80 isn't listening, despite the website's config file saying to do so:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *               LISTEN      702/systemd-resolve
tcp        0      0    *               LISTEN      1211/sshd
tcp        0      0*               LISTEN      1326/mysqld
tcp6       0      0 :::21                   :::*                    LISTEN      1005/vsftpd
tcp6       0      0 :::22                   :::*                    LISTEN      1211/sshd

When I run nginx -t, I get this:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
nginx: configuration file /etc/nginx/nginx.conf test is successful

When I run service nginx status, I get the following line, among others (none of which include "off" or "disabled"):

Active: active (running) since Sat 2018-11-24 10:47:48 UTC; 5h 38min ago

So I know that nginx is running, the syntax of the configuration files is correct, the config file for the particular website says to listen on port 80, and the config file is symlinked in /sites-enabled

  • Your netstat output is literally telling you that nginx is not listening on port 80. You need to check for firewalls, or cfg errors. service nginx says it is running, what does a ps |grep nginx say? This sure seems like a firewall issue, cfg issue, or a permissions issue, at first glance. My suggestion in order would be: check the firewall (actively, like iptables -L for example) and then I would backup your anneliesephotos config and make it a minimal config with no extras and see if it works.
    – number9
    Nov 26, 2018 at 15:10
  • @number9 Thanks. ps | grep nginx does not return any results. When I try to start nginx by entering /usr/sbin/nginx, I don't get any errors, but I still don't get any results from ps | grep nginx
    – Ethan
    Nov 26, 2018 at 15:36
  • Try ps aux, as ps will only show your user and terminal. Again, did you check your firewall?
    – number9
    Nov 26, 2018 at 16:47
  • When I run ps aux | grep nginx, there are 9 lines returned, 3 of which are master processes and the rest are worker processes. iptables -L returns this: Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
    – Ethan
    Nov 26, 2018 at 16:58
  • If your process is running and there is no firewall, it should be running and show up in netstat. I wonder if nginx does not like something in the config which is stopping it from listening, but it is still running. Did you try deleting your anneliesephotos.com config and just working with a stock config?
    – number9
    Nov 26, 2018 at 17:17

1 Answer 1


I ended up uninstalling, reinstalling, and reconfiguring nginx. There wasn't that much to reconfigure, just a couple lines in the anneliesephotos config file. But that didn't fix it.

I found that I couldn't even ping the website from outside of the network. I checked my router and it said that it was allowing all traffic to the web server, but it clearly was not. I reconfigured the router to allow only the protocols I needed. Then I rebooted the router and it started letting traffic through.

I finished reconfiguring nginx to serve the website. I also had to change

try_files $uri $uri/ =404;


try_files $uri $uri/ /index.php?q=$uri&$args;

and now it's working again.

  • That is good news. Just remember to start at the beginning... "are my packets getting there"? As crazy as this sounds, sometimes that is putting a packet sniffer on the box or looking at tcpdump and seeing if your packets are making it. In your case, trying to connect by hand from the outside would have given you a big clue. Glad to hear it works now.
    – number9
    Dec 3, 2018 at 20:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .