端口80的Nginx错误 [英] Nginx error with port 80

查看:122
本文介绍了端口80的Nginx错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的Django应用程序运行在一个VPS上,我做了一切根据本教程,但是我收到了502错误。



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

  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()到0.0.0.0 :80失败(98:地址已经在使用)
nginx:[emerg] bind()到[::]:80失败(98:地址已经在使用)
nginx:[emerg] bind )到0.0.0.0:80失败(98:地址已在使用)
nginx:[emerg] bind()到[::]:80失败(98:地址已在使用)
nginx: [emerg] bind()到0.0.0.0:80失败(98:地址已经在使用)
nginx:[emerg] bind()到[::]:80失败(98:地址已在使用)
nginx:[emerg] bind()到0.0.0.0: 80失败(98:地址已被使用)
nginx:[emerg] bind()到[::]:80失败(98:地址已在使用)
nginx:[emerg] bind()到0.0.0.0:80失败(98:地址已经在使用)
nginx:[emerg] bind()到[::]:80失败(98:地址已在使用)
nginx:[出现]仍然无法bind()`

我的Nginx配置:

  server {
server_name 95.85.34.87;

access_log关闭;

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

位置/ {
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 =所有DSP COR PSA PSDA我们的或不是UNI COM NAV';
}
}

有没有人可以帮助我?

解决方案

我在 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。


I am trying to get my Django app running on a VPS and I did everything according to this tutorial, but I am getting a 502 error.

I assume that nginx is listening to port 80 (am I right?), because sudo netstat -nlp | grep 80 throws:

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

But when I enter sudo nginx it seems that Nginx is not listening to port 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()`

My Nginx configuration:

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"';
}
}

Could anyone help me ?

解决方案

What I see in your netstat output is that nginx is already running on your system. On systems like Debian or Ubuntu, and probably other *nix systems, when you install nginx it is installed so that it starts when the system boots. Then when you try to run it from the command line you are running a second instance that tries to use the same port as the instance that starts at boot time. On Debian or Ubuntu systems you can stop nginx from starting by doing:

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

Removing the default prevents it from starting again. That default file is a symlink to /etc/nginx/sites-available/default so you can easily recreate it if needed.

Or if you want to keep the nginx that starts at boot running on its port, you could use a configuration for your nginx started from the command line that uses a different port, for instance:

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

Additional note: If you put your site in /etc/nginx/sites-enabled/ then you must not start your instance of nginx from the command line. You should control nginx only through sudo service nginx [...].

这篇关于端口80的Nginx错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆