如何用gunicorn和bokeh服务configurationNginx
我想提供一个使用我的本地networking上的服务器的embedded式散景服务的应用程序。 为了说明,我使用了散景服务示例和泊坞窗图像来复制服务器。 Docker镜像运行Nginx和Gunicorn。 我认为有一个问题,我的nginxconfiguration路由请求到/ bkapp uri。
我已经详细解决了这个问题,并提供了以下git仓库中的所有源代码
我已经开始关于散景谷歌组的讨论
单容器
为了降低在自己的容器中运行nginx的复杂性,我构build了这个图像,它运行在与web应用程序相同的容器中的nginx
安装
注意:我正在使用Docker版本17.09.0-ce
下载或克隆回购,并导航到这个目录(single_container)。
# as root docker build -f Dockerfile -t single_container .
build立
在新容器中启动terminal会话
# as root docker run -ti single_container:latest
在新的容器中启动nginx
nginx
现在开始gunicorn
gunicorn -w 1 -b :8000 flask_gunicorn_embed:app
开始
在一个单独的terminal(在主机上)find您正在运行的single_container容器的IP地址
#as root docker ps # then do copy CONTAINER ID and inspect it docker inspect [CONTIANER ID] | grep IPAddress
找
问题
使用上面发现的IP(与容器运行)在检查员与Firefox检查。 正如你可以在上面的截图(截图文件夹“single_container_broken.png”为原始get请求只是挂起
broke_1
我可以通过导航到/ bkapp / static /来validationnginx正在为静态文件提供服务(请参阅用于configuration的bokeh_recipe / single_container / nginx / bokeh_app.conf)
静态的
另一个奇怪的是,我试图直接撞到embedded式的散景服务器(使用/ bkapp /),但是我最终得到了400(否认?)
bkapp
关于应用程序
- 为了减less为龙卷风工作者dynamic分配可用端口的复杂性,我在46518硬编码端口与散景服务交谈
nginxconfiguration
我知道你可以看看bokeh_recipe / single_container / nginx / bokeh_app.conf,但我想在这里展示它。 我想我需要configurationnginx来明确说明bkapp到127.0.0.1:46518的“请求”源自服务器而不是客户端。
## Define the parameters for a specific virtual host/server server { # define what port to listen on listen 80; # Define the specified charset to the “Content-Type” response header field charset utf-8; # Configure NGINX to deliver static content from the specified folder # NOTE this should be a docker volume shared from the bokehrecipe_web container (css, js for bokeh serve) location /bkapp/static/ { alias /home/flask/app/web/static/; autoindex on; } # Configure NGINX to reverse proxy HTTP requests to the upstream server (Gunicorn (WSGI server)) location / { proxy_pass http://127.0.0.1:8000; 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; } # deal with the http://127.0.0.1/bkapp/autoload.js (note hard coded port for now) location /bkapp/ { proxy_pass http://127.0.0.1:46518; } }