Not enough workers when trying to access a site with NGINX

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/

Answer

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.

Attribution
Source : Link , Question Author : NeoChiri , Answer Author : Piotr P. Karwasz

Leave a Comment