<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Message: 2<br>
Date: Fri, 12 May 2017 13:33:16 +0300<br>
From: "Reinis Rozitis" <<a href="mailto:r@roze.lv">r@roze.lv</a>><br>
To: <<a href="mailto:nginx@nginx.org">nginx@nginx.org</a>><br>
Subject: Re: Reverse-proxying: Flask app with Bokeh server on Nginx<br>
Message-ID: <<wbr>EE53C663F45C44159B5944975E0514<wbr>DF@Neiroze><br>
Content-Type: text/plain; format=flowed; charset="UTF-8";<br>
reply-type=original<br>
<br>
> I understand that I might have to use a method called reverse proxying,<br>
> which is described here. However, I wasn't able to get it to work.<br>
<br>
Well you already do this "method called reverse proxying" with the Flask app<br>
so you have to do the same with the Bokeh app as all modern/current browsers<br>
require all resources on a HTTPS website to be also loaded through secure<br>
channels.<br>
<br>
<br>
> Does anybody have an idea how to solve this? A similar problem was<br>
> described here.<br>
<br>
You can basically copy the configuration from the SO thread you linked<br>
(obviously you can change the location names as you wish / they just need to<br>
match):<br>
<br>
In nginx add:<br>
<br>
location /bokeh/ {<br>
proxy_pass <a href="http://127.0.1.1:5006" rel="noreferrer" target="_blank">http://127.0.1.1:5006</a>;<br>
<br>
# .. with the rest of directives<br>
}<br>
<br>
relaunch the Bokeh app with<br>
<br>
--prefix=/bokeh/<br>
<br>
and (if takes part in the url construction rather than application<br>
background requests) change the url variable in the Flask app<br>
<br>
url='http://###.###.###.##:<wbr>5006'<br>
to<br>
url='<a href="https://yourserver/bokeh/" rel="noreferrer" target="_blank">https://yourserver/bokeh/</a><wbr>'<br>
<br>
or even just relative url='/bokeh/' .. (I'm not familiar with this software<br>
stack so you have to test yourself)<br>
<br></blockquote><div><br></div><div>Thanks Reinis for you quick reply.</div><div><br></div><div>I did the changes you suggested. </div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">1. in '/etc/nginx/sites-available/default' I added a new location as follow:</blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="monospace, monospace">location /bokeh/ {</font></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="monospace, monospace"> proxy_pass <a href="http://127.0.0.1:5006">http://127.0.0.1:5006</a>; # you suggested 127.0.<b>1</b>.1, but I figured that was a typo</font></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="monospace, monospace"> proxy_redirect off;</font></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="monospace, monospace"> proxy_set_header Host $http_host;</font></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="monospace, monospace"> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</font></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><font face="monospace, monospace">} </font></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><div>2. in '/etc/supervisor/conf.d/bokeh_serve.conf' I added --prefix=/bokeh/:</div></div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">[program:bokeh_serve]</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">command=/opt/envs/virtual/bin/bokeh serve company_abc.py company_xyz.py geomorphix.py --prefix=/bokeh/ --allow-websocket-origin=<a href="http://www.example.com">www.example.com</a> --allow-websocket-origin=<a href="http://example.com">example.com</a> --host=<a href="http://138.197.132.46:5006">138.197.132.46:5006</a> --use-xheaders</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">directory=/opt/webapps/flask_telemetry</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">autostart=false</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">autorestart=true</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">startretries=3</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">user=nobody</font></div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div> 3. in the Flask app, I changed the URL to:</div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">url='<a href="https://138.197.132.46:5006/bokeh/">https://138.197.132.46:5006/bokeh/</a>'</span></div></div></div></blockquote></blockquote><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace"><br></span></div><div><font face="arial, helvetica, sans-serif">Now, when I open the app in the browser I get a 502 Bad Gateway, and the Flask log file says the following: </font></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><div><font face="monospace, monospace">raise IOError("Cannot pull session document because we failed to connect to the server (to start the server, try the 'bokeh serve' command)")</font></div></div></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace">IOError: Cannot pull session document because we failed to connect to the server (to start the server, try the 'bokeh serve' command)</font></div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div style="font-family:arial,helvetica,sans-serif">However, when I go to the page http://###.###.##.##:5006/bokeh/geomorphix, the app works fine.</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Do you have an idea what's going on?</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Cheers,</div><div style="font-family:arial,helvetica,sans-serif">Julian</div></div></div></div>