Reverse-proxying: Flask app with Bokeh server on Nginx

From a different support group I got the advise to start the Bokeh server with --prefix=/bokeh/ and then create a bokeh location block in the Nginx config file. Furthermore, it was suggested to have the --host IP address (bokeh serve) and the proxy_pass IP (in Nginx config) identical. With these changes, the location block in the Nginx config file reads as follows:
location /bokeh/ {

proxy_pass http://127.0.0.1:5006;

proxy_redirect off;

proxy_set_header Host $http_host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection “upgrade”;

}

``

Then I changed the bokeh serve options as follows:

bokeh serve company_abc.py --prefix=/bokeh/ --allow-websocket-origin=www.example.com --allow-websocket-origin=example.com --host=www.example.com --host=127.0.0.1:5006 --use-xheaders

``

Note that I added www.geomorphix.net as host, because without it I got an error saying that this address wasn’t in the host whitelist.

I also changed the corresponding route in the Flask app as follows:

def company_abc():

url=‘http://127.0.0.1:5006/bokeh

session=pull_session(url=url,app_path="/company_abc")

url_https=‘https://www.example.com/bokeh

bokeh_script=autoload_server(None,app_path="/company_abc",session_id=session.id,url=url_https)

return render_template(“company_abc.html”, bokeh_script=bokeh_script)

``

With these settings I got the following error message in the Chrome console:

Bokeh: BokehJS not loaded, scheduling load and callback at Mon May 15 2017 15:05:08 GMT+0200 (W. Europe Daylight Time)

autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy…:51 Bokeh: injecting script tag for BokehJS library: http://www.example.com/bokeh/static/js/bokeh.min.js?v=9d3af13f493d36073a89714f6a5240c6

autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy…:52 Mixed Content: The page at ‘https://example.com/company_abc/’ was loaded over HTTPS, but requested an insecure script ‘http://www.example.com/bokeh/static/js/bokeh.min.js?v=9d3af13f493d36073a89714f6a5240c6’. This request has been blocked; the content must be served over HTTPS.

load_libs @ autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy…:52

(anonymous) @ autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy…:101

(anonymous) @ autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy…:106

autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy…:49 failed to load library http://www.example.com/bokeh/static/js/bokeh.min.js?v=9d3af13f493d36073a89714f6a5240c6

s.onerror @ autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy…:49

load_libs @ autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy…:52

(anonymous) @ autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy…:101

(anonymous) @ autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy…:106

``

The ‘bokeh serve’ log file reads as follows:

2017-05-15 13:04:57,517 Starting Bokeh server version 0.12.4

2017-05-15 13:04:57,526 Starting Bokeh server on port 5006 with applications at paths [’/company_abc’, ‘/company_xyz’, ‘/geomorphix’]

2017-05-15 13:04:57,526 Starting Bokeh server with process id: 5102

2017-05-15 13:05:03,029 WebSocket connection opened

2017-05-15 13:05:03,909 ServerConnection created

2017-05-15 13:05:08,602 200 GET /bokeh/company_abc/autoload.js?bokeh-autoload-element=50558e41-0bea-4759-8368-e6581a7beb43&bokeh-session-id=chm4gGmyJy2QLqxmt2SSAdetgg51fFe0uFnMTsLAnp4 (72.142.78.202) 16.24ms

``

And the Flask log file looks like this:

[2017-05-15 13:04:51 +0000] [5091] [INFO] Starting gunicorn 19.6.0

[2017-05-15 13:04:51 +0000] [5091] [INFO] Listening at: http://0.0.0.0:8118 (5091)

[2017-05-15 13:04:51 +0000] [5091] [INFO] Using worker: sync

[2017-05-15 13:04:51 +0000] [5096] [INFO] Booting worker with pid: 5096

``