Nginx on Ubuntu giving “address already in use” error

元气小坏坏 提交于 2019-12-13 05:13:30

问题


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() to 0.0.0.0:80 failed (98: Address already in use)

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

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

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/*;
}

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

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() 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.


回答1:


Try using netstat -lnp to determine the program bound to that port.




回答2:


You have something else running on port 80, use netstat -ntlp| grep :80 to find out what:

[root@TIAGO-TEST ~]# netstat -ntlp | grep :80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      21224/ngin



回答3:


I found the solution: My setting of port 3001 in the Meteor Up config hadn't been implemented. I needed to run mup setup & mup deploy again to switch from its default of 80 to port 3001. After that, it worked.



来源:https://stackoverflow.com/questions/29524067/nginx-on-ubuntu-giving-address-already-in-use-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!