端口80的Nginx错误

时间:2014-04-18 22:03:32

标签: linux django nginx

我想让我的Django应用程序在VPS上运行,我做了所有事情according to this tutorial,但我收到了502错误。

我假设nginx正在侦听端口80(我是对的吗?),因为sudo netstat -nlp | grep 80抛出:

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      892/nginx
tcp6       0      0 :::80                   :::*                    LISTEN      892/nginx
unix  2      [ ACC ]     STREAM     LISTENING     8942     805/acpid           /var/run/acpid.socket

但是当我输入sudo nginx时,似乎Nginx 不是正在侦听端口80 ......:

`nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()`

我的Nginx配置:

server {
server_name 95.85.34.87;

access_log off;

location /static/ {
    alias /opt/myenv/static/;
}

location / {
    proxy_pass http://127.0.0.1:8001;
    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"';
}
}

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

我在netstat输出中看到的是,nginx已经已在您的系统上运行。在Debian或Ubuntu等系统上,可能还有其他* nix系统,安装nginx时会安装它,以便在系统启动时启动。然后,当您尝试从命令行运行它时,您正在运行第二个实例,该实例尝试使用与启动时启动的实例相同的端口。在Debian或Ubuntu系统上,您可以通过执行以下操作来阻止nginx开始:

$ sudo service nginx stop
$ sudo rm /etc/nginx/sites-enabled/default

删除默认值会阻止它再次启动。该默认文件是/etc/nginx/sites-available/default的符号链接,因此您可以根据需要轻松地重新创建它。

或者,如果您想在其端口上保持启动时启动的nginx,您可以使用从使用其他端口的命令行启动的nginx配置,例如:

server {
        listen 3333 default_server;
        listen [::]:3333 default_server ipv6only=on;

附加说明:如果您将网站放在/etc/nginx/sites-enabled/,则必须才能从命令行启动您的nginx实例。您应该只通过sudo service nginx [...]来控制nginx。