nginx:在 "listen" 指令的 "localhost:8004" 中找不到 [emerg] 主机
nginx: [emerg] host not found in "localhost:8004" of the "listen" directive
我正在使用 nginx
和 gunicorn
开发一个 django 驱动的应用程序。
一切都很好,直到今天我试图重新启动 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
这是 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/;
}
}
我认为 8004
端口可能存在一些冲突。所以我检查了其他的 congfig 文件,没有冲突。
我想知道是什么导致了这个错误?
不需要localhost:8004
。只需要
listen 8004;
这个smart answer是我的解决方案
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.
我的问题是我试图将自定义主机“my-website.test”添加到 nginx 配置中。
我首先要做的是修改我的 /etc/hosts
并在其中添加“my-website.test”。
之后我的 nginx 运行 成功了。
我正在使用 nginx
和 gunicorn
开发一个 django 驱动的应用程序。
一切都很好,直到今天我试图重新启动 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
这是 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/;
}
}
我认为 8004
端口可能存在一些冲突。所以我检查了其他的 congfig 文件,没有冲突。
我想知道是什么导致了这个错误?
不需要localhost:8004
。只需要
listen 8004;
这个smart answer是我的解决方案
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.
我的问题是我试图将自定义主机“my-website.test”添加到 nginx 配置中。
我首先要做的是修改我的 /etc/hosts
并在其中添加“my-website.test”。
之后我的 nginx 运行 成功了。