Nginx Load balancing Issue in Linux Environment


Nginx load balancing for our application works in Windows, however when we try to run the same in

  • Linux we are getting the following error;

2021/08/12 15:11:38 [error] 14615#0: *2 open() “/usr/local/nginx/html/charts/bar_stack” failed (2: No such file or directory), client: 10.61.44.155, server: localhost, request: “GET /charts/bar_stack?parms=%7B%22object_id%22:4,%22columns%22:%7B%22x%22:%22petal_length%22,%22y%22:%22petal_width%22%7D,%22columns_type%22:%7B%22x%22:%22float64%22,%22y%22:%22float64%22%7D,%22value%22:%22None%22,%22chart_type%22:%22barstack%22,%22aggregate%22:%7B%22x%22:%22sum%22,%22y%22:%22None%22%7D,%22legends%22:%7B%22color%22:%22petal_length%22,%22size%22:%22None%22,%22shape%22:%22None%22%7D,%22valueaggregate%22:%22None%22,%22filter%22:%22None%22,%22screen%22:%22None%22,%22user_id%22:1%7D HTTP/1.1”, host: “localhost”

In the windows environment when we request for “/charts” end-point we hit the the bokeh.conf and the request is then handled by the running 2302/3/4 rest_server_charts services. But THE SAME SETUP in Linux it is trying to look up for “/charts” in “/usr/local/nginx/html/charts/bar_stack” which is not correct.

We have followed the following configuration steps to setup NGINX in both Linux and Windows environments;

In the Windows environment, we have followed the official document for installation of Nginx [Load balancing with Nginx], provided on the official bokeh website. Installation in Windows;

upstream bokehnginx {
    server localhost:2302;
    server localhost:2303;
    server localhost:2304;
}
server {
    listen 80;
    server_name localhost;
location /charts {
    proxy_pass http://bokehnginx/charts;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host:$Server_port;
    proxy_buffering off;
    }
}
  • Include the below line in nginx.conf file.
  • < include D:/XXXXX/XXXXX/bokeh.conf; >
  • Setup the rest_server_charts.py code accordingly.
  • Run the 3 rest_server_charts services for 2302/3/4 separately.
  • With this when we make calls from our application;
  • Application URL
 <http://localhost:2302/charts/bar_stack?parms=%7B%22object_id%22:4,%22columns%22:%7B%22x%22:%22petal_length%22,%22y%22:%22petal_width%22%7D,%22columns_type%22:%7B%22x%22:%22float64%22,%22y%22:%22float64%22%7D,%22value%22:%22None%22,%22chart_type%22:%22barstack%22,%22aggregate%22:%7B%22x%22:%22sum%22,%22y%22:%22None%22%7D,%22legends%22:%7B%22color%22:%22petal_length%22,%22size%22:%22None%22,%22shape%22:%22None%22%7D,%22valueaggregate%22:%22None%22,%22filter%22:%22None%22,%22screen%22:%22None%22,%22user_id%22:1%7D>
  • Calling the charts via NGINX:  it will internally pick up the ports mapped according to the configuration.
 <http://localhost:/charts/bar_stack?parms=%7B%22object_id%22:4,%22columns%22:%7B%22x%22:%22petal_length%22,%22y%22:%22petal_width%22%7D,%22columns_type%22:%7B%22x%22:%22float64%22,%22y%22:%22float64%22%7D,%22value%22:%22None%22,%22chart_type%22:%22barstack%22,%22aggregate%22:%7B%22x%22:%22sum%22,%22y%22:%22None%22%7D,%22legends%22:%7B%22color%22:%22petal_length%22,%22size%22:%22None%22,%22shape%22:%22None%22%7D,%22valueaggregate%22:%22None%22,%22filter%22:%22None%22,%22screen%22:%22None%22,%22user_id%22:1%7D>

windows - nginx.conf

#user  nobody;
worker_processes  1;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8080;
        server_name  localhost;
        location / {
             root html;
             index  index.html index.htm;
         }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    include D:/XXXXX/XXXXX/services/bokeh.conf;
 }

We have followed the exact same approach in Linux as well but for installation of Nginx, in this environment.

The rest of the steps are, similar to just as we followed in the Windows environment.

linux - nginx.conf

#user  nobody;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    server {
        listen       80;
        server_name  localhost;
        location / {
             root html;
             index  index.html index.htm;
         }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    include /opt/XXXXX/XXXXX/services/bokeh.conf;
}

Stackoverflow: https://stackoverflow.com/questions/68759620/nginx-bokeh-load-balancing-issue

@Nikhil_I This is definitely an nginx configuration issue. The path /usr/local/nginx/html/ is not anything Bokeh does or even could possibly know anything about. Instead, it is (AFAIK) exactly the path that corresponds with location / { root html; ...} that you configured. I am not why the second include server block is working on one platform but not another but to be honest, I am also not sure that server bocks can be “split up” like that, i.e. the “working” case might possibly be relying on some undefined behavior and only be working accidentally. This is really a question that would be better asked on an nginx forum where there are folks with more nginx expertise (e.g. I have very little, myself).

1 Like

Hi Bryan,

Finally we were able to fix the nginx issue, we were using “include Disk:/XXXX/XXXX/bokeh.conf” to maintain modularity. But once we have edited nginx.conf with necessary endpoint configuration instead of bokeh.conf, the issue got resolved.

Thank you.

1 Like

@Nikhil_I I’m glad to hear you found a solution. As a courtesy please self-answer (or delete) your question on SO to keep the [bokeh] tag there tidy.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.