Reverse-proxying: Flask app with Bokeh server on Nginx

J K cas.xyz at googlemail.com
Fri May 12 14:28:12 UTC 2017


>
> Message: 2
> Date: Fri, 12 May 2017 13:33:16 +0300
> From: "Reinis Rozitis" <r at roze.lv>
> To: <nginx at nginx.org>
> Subject: Re: Reverse-proxying: Flask app with Bokeh server on Nginx
> Message-ID: <EE53C663F45C44159B5944975E0514DF at Neiroze>
> Content-Type: text/plain; format=flowed; charset="UTF-8";
>         reply-type=original
>
> > I understand that I might have to use a method called reverse proxying,
> > which is described here. However, I wasn't able to get it to work.
>
> Well you already do this "method called reverse proxying" with the Flask
> app
> so you have to do the same with the Bokeh app as all modern/current
> browsers
> require all resources on a HTTPS website to be also loaded through secure
> channels.
>
>
> > Does anybody have an idea how to solve this? A similar problem was
> > described here.
>
> You can basically copy the configuration from the SO thread you linked
> (obviously you can change the location names as you wish / they just need
> to
> match):
>
> In nginx add:
>
> location /bokeh/ {
>     proxy_pass http://127.0.1.1:5006;
>
>     # .. with the rest of directives
> }
>
> relaunch the Bokeh app with
>
> --prefix=/bokeh/
>
> and (if takes part in the url construction rather than application
> background requests) change the url variable in the Flask app
>
> url='http://###.###.###.##:5006'
> to
> url='https://yourserver/bokeh/'
>
> or even just relative url='/bokeh/' .. (I'm not familiar with this software
> stack so you have to test yourself)
>
>
Thanks Reinis for you quick reply.

I did the changes you suggested.

1. in '/etc/nginx/sites-available/default' I added a new location as follow:

location /bokeh/ {

                   proxy_pass http://127.0.0.1:5006;  # you suggested 127.0.
*1*.1, but I figured that was a typo

                   proxy_redirect off;

                   proxy_set_header Host $http_host;

                   proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;

}

2.  in '/etc/supervisor/conf.d/bokeh_serve.conf' I added --prefix=/bokeh/:

[program:bokeh_serve]

command=/opt/envs/virtual/bin/bokeh serve company_abc.py company_xyz.py
geomorphix.py --prefix=/bokeh/ --allow-websocket-origin=www.example.com
--allow-websocket-origin=example.com --host=138.197.132.46:5006
--use-xheaders

directory=/opt/webapps/flask_telemetry

autostart=false

autorestart=true

startretries=3

user=nobody

 3. in the Flask app, I changed the URL to:

url='https://138.197.132.46:5006/bokeh/'


Now, when I open the app in the browser I get a 502 Bad Gateway, and the
Flask log file says the following:

raise IOError("Cannot pull session document because we failed to connect to
the server (to start the server, try the 'bokeh serve' command)")

IOError: Cannot pull session document because we failed to connect to the
server (to start the server, try the 'bokeh serve' command)

However, when I go to the page http://###.###.##.##:5006/bokeh/geomorphix,
the app works fine.

Do you have an idea what's going on?

Cheers,
Julian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20170512/3c26cdeb/attachment.html>


More information about the nginx mailing list