0

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.

Josh
  • 303
  • 3
  • 13
  • Do you have anything else running that could be bound to port 80 like Apache? – Explosion Pills Apr 08 '15 at 19:58
  • It says node is running on port 80. How do I change that? Does it need to be running on that port? – Josh Apr 08 '15 at 20:02
  • Kill whatever process is running node on port 80 and go from there. – Explosion Pills Apr 08 '15 at 20:05
  • In my previous comment, I stated that node is running on port 80. This is a meteor app, which runs on node, so node needs to be running on the server. – Josh Apr 08 '15 at 22:53
  • This server is using Nginx.... my entire question is about Nginx. Apache is not on this server. Node is running on port 80. Should I post a different question about why node is on port 80 and how to make Nginx work with it? – Josh Apr 08 '15 at 22:58
  • If node is running on port 80, then nginx cannot run on port 80. Make node/meteor run on port 3001 instead, then start nginx and it can bind to port 80 and proxy requests to port 80 to your node app on port 3001 – Explosion Pills Apr 08 '15 at 23:03
  • How do I make it run on a different port? I already told it to use port 3001 in the Meteor Up config file. – Josh Apr 08 '15 at 23:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/74769/discussion-between-explosion-pills-and-josh). – Explosion Pills Apr 08 '15 at 23:34

4 Answers4

0

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

phunktrain
  • 61
  • 3
0

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
Tiago Lopo
  • 7,619
  • 1
  • 30
  • 51
0

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.

Josh
  • 303
  • 3
  • 13
0

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

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

kill ${PID}

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 is the default port used by http, it's ok to change it

then start your nginx

$ nginx -c /path/to/your/nginx.conf
chie
  • 291
  • 3
  • 4