Nginx的错误端口80(Nginx error with port 80)

2019-10-19 22:28发布

我试图让一个VPS我的Django应用程序运行,我所做的一切都是根据这个教程 ,但我得到一个502错误。

我认为nginx的是侦听端口80(是吗?),因为sudo netstat -nlp | grep 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"';
}
}

谁能帮我?

Answer 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的实例。 您应该只通过控制nginx的sudo service nginx [...]



文章来源: Nginx error with port 80