MacBook Pro affichant un éditeur de code

Nginx – Configuration Error – Connection Refused

When setting up nginx it can happen that afterwards it is not possible to connect to the server and that you receive a “hostname not found” error

In the terminal, we start by using

curl -v domain.dev

The error appears

 Rebuilt URL to: domain.dev/
Hostname was NOT found in DNS cache
Trying 127.0.0.1...
connect to 127.0.0.1 port 80 failed: Connection refused
Failed to connect to domain.dev port 80: Connection refused
Closing connection 0
curl: (7) Failed to connect to domain.dev port 80: Connection refused

We can try to restart nginx

sudo service nginx restart

in case of failure

nginx -t

correct the error found, it should be explicit.

then check that nginx is actually listening on port 80

sudo netstat -tulpn grep 80
tcp 0 0.0.0.0:80 0.0.0.0:LISTEN 20621/nginx     
tcp6 0 0 :::80 :::* LISTEN 20621/nginx 

if not, check that the links are properly made from sites-enabled to sites-available

to do it automatically

    for host in /etc/nginx/sites-available/ Do
        sudo ln -sf $-host
    Done

Leave a comment