Nginx Reverse Proxy Example


I am relativly new to bokeh. But i worked before with django. But i wanted to try out Bokeh. Actually I have a bokeh app finished reading sensor data on a raspberry pi 4 with ubuntu server 22 installed.
Now what I am trying is to make the reverse proxy connection using nginx like provided in the documentation but what I get is a blank white page.

I have controlled with mozilla developer tools.

Maybe a clean and better documentation or basic example on how to reverse proxy with nginx would be fine.

With kind regards

Hi PeterM1,

I struggled with this a couple of years ago and now have dozens of bokeh servers running behind nginx reverse proxy on several servers and found a recipe that works for bokeh server, nginx reverse proxy and django/gunicorn with a FQDN SSL website.

I still have no idea exactly what is behind the nginx magic but I found I needed both the URL and websocket in the nginx code and to take care with ‘/’ between bokeh, nginx and django URLs.

As concrete example assume you run a standard bokeh server for example like this (inside a systemd.service):-

bokeh serve flight --allow-websocket-origin=‘’ --use-xheaders --port=5007 --prefix=‘/flight’

this nginx location allows the URL to be reverse proxied at

location /flight {
#rewrite ^/flight(.*) $1 break;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_buffering off;

BUT you’ll need a second websocket (wss) location like below which handles django call-back and stuff AFAIK:-

location = /flights {
	proxy_pass http://unix:/run/gunicorn.sock;

And then in django you have corresponding view and template to provide the frontend:-

def flights(request):
script = server_document(url=aurl)
my_dict={‘Intro’ : ‘Live flight tracker, Choose an airport : wait 5 seconds’, ‘script’: script}
return render(request, ‘home/test_server.html’,my_dict)

The test_server.html is like bokeh docs examples but you must ensure to load the right version of bokeh in the scripts compared to your bokeh server or you might get blank page.

hope it helps

Hi thank you for your reply. I will try the things you suggested

1 Like