Ubuntu上的Nginx提供“地址已在使用中"错误 [英] Nginx on Ubuntu giving "address already in use" error

查看:208
本文介绍了Ubuntu上的Nginx提供“地址已在使用中"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置我的VPS(DigitalOcean上的Ubuntu)以运行Meteor应用程序,但在处理Nginx配置时却遇到了障碍.当我尝试重新启动Nginx时,为了使其为域名加载新的.conf文件,它显示此错误:

I'm trying to setup my VPS (Ubuntu on DigitalOcean) to run Meteor apps but am hitting a snag early on dealing with Nginx configuration. When I attempt to restart Nginx, in order for it to load a new .conf file for a domain name, it shows this error:

[emerg] 3597#0:将bind()设置为0.0.0.0:80失败(98:地址已在使用中)

[emerg] 3597#0: bind() to 0.0.0.0:80 failed (98: Address already in use)

它在日志中重复5次,并以:结尾

It repeats it 5 times in the logs and ends with:

[emerg] 3597#0:仍然无法绑定()

[emerg] 3597#0: still could not bind()

这是Nginx主要配置(/etc/nginx/nginx.conf)的转储:

Here's a dump of Nginx's main config (/etc/nginx/nginx.conf):

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml $

        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
        ##

        #include /etc/nginx/naxsi_core.rules;

        ##
        # nginx-passenger config
        ##
        # Uncomment it if you installed nginx-passenger
        ##

        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

站点可用目录或启用站点的目录(包括默认"站点)中没有任何内容,因为我的理解是流星(通过Node)将为应用程序提供服务,因此我们从Nginx需要的是虚拟主机处理.我的应用程序名为Loyr,所以我创建了/etc/nginx/conf.d/loyr.conf:

I don't have anything in the sites-available or sites-enabled directories (including a 'default' site) because my understanding is that Meteor (via Node) will serve the app instead, so all we need from Nginx is virtual host handling. My app's name is Loyr so I created /etc/nginx/conf.d/loyr.conf:

server {
 listen 80;

 server_name loyr.co;

 location / {
 proxy_pass http://localhost:3001;
 proxy_http_version 1.1;
 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection ‘upgrade’;
 proxy_set_header Host $host;
 proxy_cache_bypass $http_upgrade;
 }
}

将该文件写入conf.d目录后,我使用了 service nginx restart 重新加载配置文件,但是它只显示"[fail].在nginx错误日志中( /var/log/nginx/error.log),则打印以下行:

After I wrote that file to the conf.d directory, I used service nginx restart to have it reload the configuration files, but it just says "[fail]. In the nginx error log (/var/log/nginx/error.log), these lines are printed:

2015/04/08 15:43:02 [emerg] 4103#0:将bind()设置为0.0.0.0:80失败(98: 地址已在使用中)2015/04/08 15:43:02 [emerg] 4103#0:bind() 0.0.0.0:80失败(98:地址已在使用中)2015/04/08 15:43:02 [emerg] 4103#0:bind()到0.0.0.0:80失败(98:地址已在使用中 使用)2015/04/08 15:43:02 [emerg] 4103#0:bind()到0.0.0.0:80失败 (98:地址已在使用中)2015/04/08 15:43:02 [emerg] 4103#0: 将bind()设置为0.0.0.0:80失败(98:地址已在使用中)2015/04/08 15:43:02 [emerg] 4103#0:仍然无法绑定()

2015/04/08 15:43:02 [emerg] 4103#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2015/04/08 15:43:02 [emerg] 4103#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2015/04/08 15:43:02 [emerg] 4103#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2015/04/08 15:43:02 [emerg] 4103#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2015/04/08 15:43:02 [emerg] 4103#0: bind() to 0.0.0.0:80 failed (98: Address already in use) 2015/04/08 15:43:02 [emerg] 4103#0: still could not bind()

非常感谢您能提供关于此问题的任何见识.

I'd really appreciate any insight you could give me on this issue.

推荐答案

查找端口80是由谁使用的.

find your port 80 is used by whom.

$ netstat -ntpl
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:49152         0.0.0.0:*               LISTEN      5968/uwsgi
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      702/mysqld
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      6127/nginx: worker
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6127/nginx: worker
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      382/systemd-resolve
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      865/sshd
tcp6       0      0 :::80                   :::*                    LISTEN      6127/nginx: worker

如果您不需要使用端口80的程序,则可以通过以下方式将其停止

If u don't need the program using port 80, u can stop it by

kill ${PID}

或者您可以像这样更改nginx.conf

Or u can change the nginx.conf like

server {
 listen 90;

 server_name loyr.co;

 location / {
 proxy_pass http://localhost:3001;
 proxy_http_version 1.1;
 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection ‘upgrade’;
 proxy_set_header Host $host;
 proxy_cache_bypass $http_upgrade;
 }
}

80是http使用的默认端口,可以更改它

80 is the default port used by http, it's ok to change it

然后启动您的nginx

then start your nginx

$ nginx -c /path/to/your/nginx.conf

这篇关于Ubuntu上的Nginx提供“地址已在使用中"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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