Ghasem
Ghasem

Reputation: 15563

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?

Upvotes: 6

Views: 10014

Answers (3)

Pavel Botsman
Pavel Botsman

Reputation: 863

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.

Upvotes: 2

Ghasem
Ghasem

Reputation: 15563

this smart answer was my solution

I assume that you're running a Linux, and you're using gEdit to edit your files. In the /etc/nginx/sites-enabled, it may have left a temp file e.g. default~ (watch the ~). Delete this file, and it will solve your problem.

Upvotes: 0

itzMEonTV
itzMEonTV

Reputation: 20339

No need of localhost:8004.Only need is

listen 8004;

Upvotes: 9

Related Questions