Bokeh App Loading Fail (Bokeh-Flask server using Nginx and Gunicorn )

I am trying to serve my html page with emmbeded bokeh app. Everthing is fine. But bokeh app use port 5006 and it is not loading to the page.
I am getting these errors:

  • WebSocket connection to ‘ws://46.101.253.40:5006/bkapp/ws?bokeh-protocol-version=1.0&bokeh-session-id=MLpmBemXpIvnNDCppcmjy7LNOq1MMJcWUia8jRDm4tmE’ failed: Error during WebSocket handshake: Unexpected response code: 403

  • [bokeh] Failed to connect to Bokeh server Error: Could not open websocket

As far as I understand, nginx handle 5000 port requests but bokeh use 5006 port additively. My server cannot handle that. I couldn’t figure out what I need to do.

My file are :

wsgi.py


from WebApp import app

if __name__ == "__main__":

app.run()

bokeh.py


from flask import Flask, render_template, request

from bokeh.embed import server_document

from bokeh.server.server import Server

from tornado.ioloop import IOLoop

from Decision_Tree.Plot.decision_tree import create_figure

app = Flask(__name__)

def modify_doc(doc):

# Create the plot

plot = create_figure()

# Embed plot into HTML via Flask Render

doc.add_root(plot)

@app.route('/', methods=['GET'])

def bkapp_page():

script = server_document('http://46.101.XXX.XX:5006/bkapp')

return render_template("index.html", script=script, template="Flask")

def bk_worker():

server = Server({'/bkapp': modify_doc}, io_loop=IOLoop(), allow_websocket_origin=["46.101.XXX.XXX:5000"])

server.start()

server.io_loop.start()

from threading import Thread

Thread(target=bk_worker).start()

if __name__ == '__main__':

app.run(host='46.101.XXX.XXX', debug=True)

gunicorn service file:


[Unit]

Description=Gunicorn instance to serve bokeh

After=network.target

[Service]

User=root

Group=www-data

WorkingDirectory=/root/bokeh

Environment="PATH=/root/bokeh/bokehenv/bin"

ExecStart=/root/bokeh/bokehenv/bin/gunicorn --workers 3 --bind unix:bokeh.sock -m 007 wsgi:app

[Install]

WantedBy=multi-user.target

nginx file:


server {

listen 80;

server_name 46.253.XXX.XXX;

access_log /tmp/bokeh.access.log;

location = /favicon.ico { access_log off; log_not_found off; }

location / {

include proxy_params;

proxy_pass http://unix:/root/bokeh/bokeh.sock;

}

location /static {

alias /root/bokeh/static;

}

}