Hello Bryan.
For now I left the idea of deploying to Heroku and trying to deploy on Digital Ocean. I have successfully done with flask+bokeh app as separate files(server_document) but need help with deploying bokeh in flask as a library. I have used this starter kit https://github.com/LunkRat/flask-bokeh-dashboard. App working locally but online loaded only flask, /bkapp gives 502 error and any js error not seen in browser console. Something wrong with ports and I don’t exactly understand how it must be. That what I have:
dashboard.py
import asyncio
except ImportError:
raise RuntimeError("This example requries Python3 / asyncio")
#################################################################
if __name__ == '__main__':
import sys
bkapp = Application(FunctionHandler(modify_doc))
sockets, port = bind_sockets("157.245.XX.XXX", 0)
###############################################################
script = server_document(
'157.245.12.139:%d/bkapp' % port,
arguments=dict(
plot_title = plot_title,
dataset = datasets.get(current_dataset),
unit_type = unit_type,
theme = theme)
################################################################
def bk_worker():
asyncio.set_event_loop(asyncio.new_event_loop())
bokeh_tornado = BokehTornado({'/bkapp': bkapp}, extra_websocket_origins=[ "157.245.XX.XXX:8000"])
bokeh_http = HTTPServer(bokeh_tornado)
bokeh_http.add_sockets(sockets)
server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http)
server.start()
server.io_loop.start()
from threading import Thread
Thread(target=bk_worker).start()
gunicorn settings:
[Unit]
Description=Gunicorn instance to serve flask embedded bokeh
After=network.target
[Service]
User=artemski
Group=www-data
WorkingDirectory=/home/artemski/dashboard
Environment="PATH=/home/artemski/envdir/myvenv/bin"
ExecStart= /home/artemski/envdir/myvenv/bin/gunicorn --workers 4 --bind unix:brew.sock -m 007 wsgi:app
[Install]
WantedBy=multi-user.target
nginx settings
server {
listen 80;
server_name 157.245.XX.XX;
access_log /tmp/bokeh.access.log;
error_log /tmp/bokeh.error.log debug;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/home/artemski/dashboard/brew.sock;
}
location /bkapp/ {
proxy_pass http://127.0.0.1:5100;
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;
}
location /bkapp/static/ {
alias /home/artemski/dashboard/static/;
}
}
bokeh error log
2019/09/27 19:49:03 [debug] 20111#20111: *1 write new buf t:1 f:0 0000560579F5DBC0, pos 0000560579F5DBC0, size: 166 file: 0, size: 0
2019/09/27 19:49:03 [debug] 20111#20111: *1 http write filter: l:0 f:0 s:166
2019/09/27 19:49:03 [debug] 20111#20111: *1 http output filter “/bkapp/?”
2019/09/27 19:49:03 [debug] 20111#20111: *1 http copy filter: “/bkapp/?”
2019/09/27 19:49:03 [debug] 20111#20111: *1 image filter
2019/09/27 19:49:03 [debug] 20111#20111: *1 xslt filter body
2019/09/27 19:49:03 [debug] 20111#20111: *1 http postpone filter “/bkapp/?” 0000560579F5DDF0
2019/09/27 19:49:03 [debug] 20111#20111: *1 write old buf t:1 f:0 0000560579F5DBC0, pos 0000560579F5DBC0, size: 166 file: 0, size: 0
2019/09/27 19:49:03 [debug] 20111#20111: *1 write new buf t:0 f:0 0000000000000000, pos 0000560579B66BA0, size: 120 file: 0, size: 0
2019/09/27 19:49:03 [debug] 20111#20111: *1 write new buf t:0 f:0 0000000000000000, pos 0000560579B680A0, size: 62 file: 0, size: 0
2019/09/27 19:49:03 [debug] 20111#20111: *1 write new buf t:0 f:0 0000000000000000, pos 0000560579B67E80, size: 402 file: 0, size: 0
2019/09/27 19:49:03 [debug] 20111#20111: *1 http write filter: l:1 f:0 s:750
2019/09/27 19:49:03 [debug] 20111#20111: *1 http write filter limit 0
2019/09/27 19:49:03 [debug] 20111#20111: *1 writev: 750 of 750
2019/09/27 19:49:03 [debug] 20111#20111: *1 http write filter 0000000000000000
2019/09/27 19:49:03 [debug] 20111#20111: *1 http copy filter: 0 “/bkapp/?”
2019/09/27 19:49:03 [debug] 20111#20111: *1 http finalize request: 0, “/bkapp/?” a:1, c:1
2019/09/27 19:49:03 [debug] 20111#20111: *1 set http keepalive handler
2019/09/27 19:49:03 [debug] 20111#20111: *1 http close request
2019/09/27 19:49:03 [debug] 20111#20111: *1 http log handler
2019/09/27 19:49:03 [debug] 20111#20111: *1 free: 0000560579F70CF0, unused: 8
2019/09/27 19:49:03 [debug] 20111#20111: *1 free: 0000560579F5CFF0, unused: 175
2019/09/27 19:49:03 [debug] 20111#20111: *1 free: 0000560579F123D0
2019/09/27 19:49:03 [debug] 20111#20111: *1 hc free: 0000000000000000
2019/09/27 19:49:03 [debug] 20111#20111: *1 hc busy: 0000000000000000 0
2019/09/27 19:49:03 [debug] 20111#20111: *1 reusable connection: 1
2019/09/27 19:49:03 [debug] 20111#20111: *1 event timer add: 3: 65000:152452091
bokeh access log
24.185.XXX.XXX - - [27/Sep/2019:19:48:53 +0000] “GET / HTTP/1.1” 200 3122 “-” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36”
24.185.XX.XXX - - [27/Sep/2019:19:48:54 +0000] “GET /static/css/lib/material.min.css HTTP/1.1” 200 141212 “http://157.245.XX.XXX/” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36”
24.185.XXX.XXX - - [27/Sep/2019:19:48:54 +0000] “GET /static/css/styles.css HTTP/1.1” 200 4808 “http://157.245.XX.XX/” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36”
24.185.118.XXX - - [27/Sep/2019:19:48:54 +0000] “GET /static/js/lib/material.min.js HTTP/1.1” 200 62491 “http://157.245.XX.XXX/” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36”
24.185.118.XXX - - [27/Sep/2019:19:48:54 +0000] “GET /static/js/lib/material.min.js.map HTTP/1.1” 404 209 “-” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36”
24.185.118.XXX- - [27/Sep/2019:19:49:02 +0000] “GET /bkapp HTTP/1.1” 301 194 “-” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36”
24.185.XXX.XXX - - [27/Sep/2019:19:49:03 +0000] “GET /bkapp/ HTTP/1.1” 502 584 “-” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36”
nginx.service status*
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-09-27 19:48:45 UTC; 43min ago
Docs: man:nginx(8)
Process: 20091 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 20104 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 20093 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 20107 (nginx)
Tasks: 2 (limit: 1109)
CGroup: /system.slice/nginx.service
├─20107 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─20111 nginx: worker process