nginx:在[listen]指令的"localhost:8004"中找不到[emerg]主机

Ale*_*lig 4 django nginx gunicorn

我正在使用nginx和开发一个django驱动的应用程序gunicorn.一切都很好,直到今天我试图重新启动nginx失败.所以我用sudo nginx -t命令测试它,我得到了这个错误.

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
Run Code Online (Sandbox Code Playgroud)

这是808配置文件内容:

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/;
    }
}
Run Code Online (Sandbox Code Playgroud)

我认为这可能与8004端口有些冲突.所以我检查了其他congfig文件,没有冲突.

我想知道什么可能导致这个错误?

itz*_*nTV 7

不需要localhost:8004.只需要

listen 8004;
Run Code Online (Sandbox Code Playgroud)


Ale*_*lig 0

这个聪明的答案是我的解决方案

我假设您运行的是 Linux,并且使用 gEdit 来编辑文件。在 中/etc/nginx/sites-enabled,它可能留下了一个临时文件,例如default~(观看~)。删除这个文件,就可以解决你的问题了。