如何使用gunicorn和bokeh服务配置Nginx

时间:2017-11-30 17:00:08

标签: docker nginx flask gunicorn bokeh

我想提供一个烧录应用程序,它使用来自我本地网络上的服务器的嵌入式散景服务。为了说明我使用bokeh serve example和docker镜像来复制服务器。码头图像运行Nginx和Gunicorn。我认为我的nginx配置将请求路由到/ bkapp uri有问题。

我详细说明了问题,并在以下git repo

中提供了所有源代码

我已开始讨论bokeh google group

单个容器

为了降低在自己的容器中运行nginx的复杂性,我构建了这个在与web应用程序相同的容器中运行nginx的映像

安装

注意:我使用的是Docker版本17.09.0-ce

下载或克隆repo并导航到此目录(single_container)。

# as root
docker build -f Dockerfile -t single_container .

build

在新容器中启动终端会话

# as root
docker run -ti single_container:latest

在新容器中启动nginx

nginx

现在开始枪炮

gunicorn -w 1 -b :8000 flask_gunicorn_embed:app

start

在一个单独的终端(在主机上)找到您正在运行的single_container容器的IP地址

#as root
docker ps
# then do copy CONTAINER ID and inspect it
docker inspect [CONTIANER ID] | grep IPAddress

find

问题

使用上面找到的IP(运行容器)在检查员的firefox中查看。 正如您在上面的截图中所见(请参阅屏幕截图文件夹“single_container_broken.png”,原始获取请求只是挂起

broke_1

我可以通过导航到/ bkapp / static /来验证nginx是否正在提供静态文件(请参阅bokeh_recipe / single_container / nginx / bokeh_app.conf以获取配置)

static

另一个奇怪的是我尝试直接点击嵌入式散景服务器(使用/ bkapp /),但我最终得到400(被拒绝?)

bkapp

关于应用

的注意事项
  • 降低为龙卷风工人动态分配可用端口的复杂性我在46518中硬编码端口与散景服务交谈

nginx config

我知道你可以看看bokeh_recipe / single_container / nginx / bokeh_app.conf,但我想在这里展示一下。 我想我需要配置nginx来明确表示对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;
    }

}

0 个答案:

没有答案
相关问题