0

I know about this similar question, but I can't seem to fix my issue reading through it.

Background

I am trying to run Chronograf via Nginx. I already have a few Nginx block running.

For this one, I follow the example here, so I set up the following file in this location: /etc/nginx/sites-available/chronograf.baseurl.com:

server {
  server_name chronograf.baseurl.com www.chronograf.baseurl.com;

  location / {
   proxy_pass http://localhost:8888/;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-Host $host;
   proxy_set_header X-Forwarded-Server $host;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

Then I check the syntax with sudo nginx -t and see that all is good:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally I run sudo systemctl restart nginx and get a failure:

Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

The /var/log/nginx/error.log posts:

2020/05/27 02:22:27 [info] 4740#4740: Using 32768KiB of shared memory for nchan in /etc/nginx/nginx.conf:63
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: still could not bind()

Can someone help me debug this?

UPDATE 1

As per the @Pandurang's suggestion:

  1. I stopped nginx by running sudo systemctl stop nginx.
  2. Then I run the ps -ef | grep nginx command.

It returns the following output:

root       846   821  0 Apr13 ?        00:45:11 runsv nginx
root       870   846  0 Apr13 ?        00:47:39 svlogd -tt /var/log/gitlab/nginx
stelian   3028  2943  0 15:47 pts/0    00:00:00 grep --color=auto nginx
root     32462   846  0 01:47 ?        00:00:00 nginx: master process /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx
gitlab-+ 32493 32462  0 01:47 ?        00:00:00 nginx: worker process
gitlab-+ 32494 32462  0 01:47 ?        00:00:00 nginx: worker process
gitlab-+ 32495 32462  0 01:47 ?        00:00:00 nginx: worker process
gitlab-+ 32496 32462  0 01:47 ?        00:01:18 nginx: worker process
gitlab-+ 32497 32462  0 01:47 ?        00:00:00 nginx: cache manager process

I suspect there is a clash between nginx and GitLab?

9
  • kill Nginx process using killall nginx and test.
    – Pandurang
    May 27, 2020 at 16:06
  • This yields: nginx: no process found. The ps -ef | grep nginx still yield the same as shown in my post above.
    – Newskooler
    May 27, 2020 at 16:16
  • Start nginx process using systemctl start nginx command.
    – Pandurang
    May 27, 2020 at 16:18
  • I cannot because it fails, due to the last update of the chronograf.baseurl.com. I get Job for nginx.service failed because the control process exited with error code.
    – Newskooler
    May 27, 2020 at 16:19
  • I think you nginx process used by gitlab.could you please kill gitlab process and test
    – Pandurang
    May 27, 2020 at 16:32

3 Answers 3

1
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)

The issue is that ports 80 and 443 are already in use somewhere: Address already in use

The next step in debugging is to identify what process is listening on (or 'bound to') the ports in question using netstat and egrep:

sudo netstat -nap | egrep ':(80|443)\s.*LISTEN'

(root privileges are required for netstat -p, which prints associated process information)

Here's an example where nginx is listening:

$ sudo netstat -nap | egrep ':(80|443)\s.*LISTEN'
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4498/nginx: worker  
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      4498/nginx: worker  
tcp6       0      0 :::80                   :::*                    LISTEN      4498/nginx: worker  
tcp6       0      0 :::443                  :::*                    LISTEN      4498/nginx: worker  
$
3
  • The result I see is: tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 32462/nginx: master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 32462/nginx: master
    – Newskooler
    May 27, 2020 at 16:18
  • I am confused because nginx is stopped and disabled. Yet I still see it listening on the above ports and this still seems to be blocking me adding another nginx block and generally all feels quite tangled.
    – Newskooler
    May 27, 2020 at 16:21
  • @Newskooler see serverfault.com/a/233250/296703
    – tomr
    May 28, 2020 at 5:58
1

use netstat -an | grep :80 command to check whether the port is used by other services or not.

3
  • I see this when I run the command tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN and the PID/Program name is 32462/nginx: master
    – Newskooler
    May 27, 2020 at 12:30
  • Looks like nginx process is running on 80 port. Stop nginx process using systemctl stop nginx command. Make sure that Nginx process stopped using ps -ef | grep nginx. Then start Nginx process using systemctl start nginx. Also make sure that you are using single entry of listen 80 and listen 443 port.
    – Pandurang
    May 27, 2020 at 13:35
  • can see my Update 1, please?
    – Newskooler
    May 27, 2020 at 15:52
0

I got this error recently, and the solution for me was that apache was also running at the same time. You can check this by

sudo systemctl status apache2

If it is running this command will stop it

sudo systemctl stop apache2

And this will prevent apache from running

sudo systemctl disable apache2
2
  • I don't have an apache2 running though. Unit apache2.service could not be found.
    – Newskooler
    May 27, 2020 at 2:37
  • I don't have enough karma to comment on your above question, but you could check what's listening on 80 by using this command sudo netstat -lnp.
    – curios
    May 27, 2020 at 3:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.