0

I am trying to create a Sonarqube in a Ubuntu virtual machine with Vagrant and using Nginx. I have followed all the steps but when I try to access I get a 502 BadGateway and checking the logs I get the following:

2020/01/29 18:44:05 [alert] 1205#1205: 768 worker_connections are not enough
2020/01/29 18:44:05 [error] 1205#1205: *2090 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: sonarqube.developerinsider.co, request: "GET /favicon.ico HTTP/1.0", upstream: "

This is the configuration I have for the site:

upstream sonar {
 server 127.0.0.1:9000;
}

server{
listen      9000;
server_name sonarqube.developerinsider.co;

access_log  /var/log/nginx/sonar.access.log;
error_log   /var/log/nginx/sonar.error.log;

proxy_buffers 16 64k;
proxy_buffer_size 128k;

location / {
    proxy_pass  http://127.0.0.1:9000;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
    proxy_redirect off;

}
}

This is my Vagrant File:

Vagrant.configure("2") do |config|
 config.vm.box = "generic/ubuntu1804"
 config.vm.box_check_update = true
 config.vm.network "private_network", ip: "XXX.XX.XX.XX"
 config.vm.network "forwarded_port", guest: 80, host: 8081, host_ip: "127.0.0.1"
 config.vm.hostname = "tracker.tlc.vm"
 config.vm.provider "virtualbox" do |vb|
 vb.memory = "4096"
end
end

However I can access the Jenkins I have in it and the Nginx's default site. I try to access using the following IP: http://XXX.XX.XX.XX:9000/

NeoChiri
  • 101
  • 1
  • Are you sure of your config? The server is listening on port `9000` and is a proxy for himself: `proxy_pass http://127.0.0.1:9000`? – Piotr P. Karwasz Jan 29 '20 at 19:04
  • I am not, I am very new in these matters so I followed the following tutorial: https://developerinsider.co/install-sonarqube-on-ubuntu/ – NeoChiri Jan 29 '20 at 19:30

1 Answers1

0

The tutorial you cite contains a typo. The Nginx config should look like

server {
    listen 80;
    ...
    location / {
        proxy_pass http://127.0.0.1:9000;
        ...
    }
}

This way nginx will be available under http://<server's IP>/, while Sonarqube under http://<server's IP>:9000/. By the way Sonarqube is not running on your server, otherwise nginx could not possibly use port 9000.

What is happening now: when a request comes, nginx forwards the request to 127.0.0.1:9000, i.e. himself. This cause an infinite loop of forwards, which ends up when nginx runs out of workers to deal with them.

You should inform the tutorial's author of the typo.

Piotr P. Karwasz
  • 5,292
  • 2
  • 9
  • 20
  • Now I get this on the logs: `31535#31535: accept4() failed (24: Too many open files)` using the IP `http://XXX.XXX.XX.XX:9000` and the browser gives this error: `400 Bad Request Request Header Or Cookie Too Large` I have checked and sonarqube is up and running. – NeoChiri Jan 29 '20 at 19:48
  • You need to restart **nginx**, so it will free port `9000` and move to port `80` and start **Sonarqube**. The site should be available as `http://XXX.XXX.XXX.XXX`. – Piotr P. Karwasz Jan 29 '20 at 19:50
  • I restarted nginx and sonarqube and using `http://XXX.XXX.XXX.XXX` is redirecting me to nginx's default site. Do I need to disable default site first? – NeoChiri Jan 29 '20 at 20:07
  • Yes, and change the listen directive to `listen 80 default;` to be sure. – Piotr P. Karwasz Jan 29 '20 at 20:12
  • I disabled the default site and changed the listen directive but I get the 404 error I mentioned above and logs show this: `accept4() failed (24: Too many open files)` – NeoChiri Jan 29 '20 at 20:18
  • Another loop must have happened. Can you read the **Sonarqube** server on `http://XXX.XXX.XXX.XXX:9000` by passing this way **nginx**? – Piotr P. Karwasz Jan 30 '20 at 03:39
  • I get the same error using that url. – NeoChiri Jan 30 '20 at 11:51
  • So it is a Sonarqube problem then (on that URL Sonarqube is listening). – Piotr P. Karwasz Jan 30 '20 at 20:07