Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx: [emerg] host not found in "localhost:8004" of the "listen" directive

I am developing a django powered application using nginx and gunicorn. Everything was fine, until today which i tried to restart nginx which failed. so I tested it with sudo nginx -t command and I got this error.

nginx: [emerg] host not found in "localhost:8004" of the "listen" directive in
/etc/nginx/sites-enabled/808:2 
nginx: configuration file /etc/nginx/nginx.conf test failed

this is 808 config file contents:

server {
    listen localhost:8004;
    error_log /var/www/html/burger808/error.log;

    location / {
        proxy_pass http://127.0.0.1:8005;
        proxy_set_header X-Forwarded-Host     $server_name;
        proxy_set_header X-Real-IP        $remote_addr;
        add_header P3P 'CP="ALL DSP COR   PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }

    location /static/ {
        autoindex on;
        alias /var/www/html/burger808/burger808/static/;
    }
    location /media/ {
        autoindex on;
        alias /var/www/html/burger808/burger808/media/;
    }
}

I thought it might be some conflicting over 8004 port. So i checked the other congfig files and there were no conflictings.

I wonder what could've caused this error?

like image 735
Alex Jolig Avatar asked Jan 07 '23 21:01

Alex Jolig


2 Answers

No need of localhost:8004.Only need is

listen 8004;
like image 118
itzMEonTV Avatar answered Jan 16 '23 21:01

itzMEonTV


My problem was that I was trying to add custom host "my-website.test" to the nginx config.
What I had to do first is to modify my /etc/hosts and add "my-website.test" there.
After that my nginx ran successfully.

like image 21
Pavel Botsman Avatar answered Jan 16 '23 20:01

Pavel Botsman