使用Nginx进行散景服务器+反向代理可获得404

时间:2016-06-28 16:18:42

标签: python nginx proxy bokeh

我试图设置一个Bokeh服务器并用Nginx反向代理它。

我的p-website.conf现在看起来像:

server {
listen   80;
server_name  website.com;
client_max_body_size 25M;
access_log  /var/www/logs/p-website.access.nginx.log;
error_log  /var/www/logs/p-website.error.nginx.log error;
root    /var/www/pydocs/website/production/src;

include global/restrictions.conf;


location /plot/ {
    proxy_pass http://website.com: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 / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    # enable this if and only if you use HTTPS, this helps Rack
    # set the proper protocol for doing redirects:
    # proxy_set_header X-Forwarded-Proto https;

    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_connect_timeout 10;
    proxy_read_timeout 60s;

    proxy_pass http://production_website_gunicorn;
}
}

在服务器上,我运行Bokeh服务器:

bokeh serve bokehserver.py --port 5100 --host website.com:80

但是当我访问website.com/plot/时,我从Bokeh获得了404,服务器终端给了我:警告:tornado.access:404 GET /("这里是ip地址")3.04ms

我不明白为什么它总是给出一个404,或者它与Nginx有什么关系?

谢谢!

更新30/06

好的,我认为我更进了一步,并希望朝着好的方向前进。 我的p-website.conf现在看起来像:

server {
listen   80 default_server;
server_name  website.com;
client_max_body_size 25M;
access_log  /var/www/logs/p-website.access.nginx.log;
error_log  /var/www/logs/p-website.error.nginx.log error;
root    /var/www/pydocs/magnify/production/src;

include global/restrictions.conf;


location / {
    allow 127.0.0.1:5100
    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;
}

}

我现在用:

运行服务器
bokeh serve bokehserver.py --port 5100 --host 127.0.0.1:80

现在我不再获得404了,但是" 403:禁止"当我去website.com:5100/bokehserver/。这个消息在bokehserver终端上:

INFO:bokeh.server.tornado:Rejected connection from host 'website.com:5100' because it is not in the --host whitelist
WARNING:tornado.access:403 GET /bokehserver/ (213.152.161.35) 0.78ms

我试图通过在p-website.conf中添加allow 127.0.0.1:5100来解决白名单问题,但没有运气。

1 个答案:

答案 0 :(得分:4)

我想通了,显然你需要在Bokeh命令中添加相同位置的--prefix =:

bokeh serve bokehserver.py --port 5100 --prefix=/plot/ --host website.com:80

p-website.conf中的位置块如下所示:

location /plot/ {
    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;
}