问题描述
我正在尝试设置一个Bokeh服务器,并使用Nginx对其进行反向代理.
I'm trying to set up a Bokeh server and reverse proxy it with Nginx.
我的p-website.conf现在看起来像:
My p-website.conf now looks like:
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服务器:
On the server I run the Bokeh server with:
bokeh serve bokehserver.py --port 5100 --host website.com:80
但是当我访问website.com/plot/时,我从Bokeh收到了404,服务器终端给了我:警告:tornado.access:404 GET/(这里是IP地址")3.04ms
But when I visit website.com/plot/ I get a 404 from Bokeh and the servers terminal gives me: WARNING:tornado.access:404 GET / ("here was ip address") 3.04ms
我不明白为什么它总是给出404,或者与Nginx有关?
I don't understand why it always gives a 404, or has it something to do with Nginx?
谢谢!
更新30/06
好吧,我想我又走了一步,并希望朝着正确的方向前进.我的p-website.conf现在看起来像:
Ok, I think I'm a step further, and hopefully in the good direction.My p-website.conf now looks like:
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;
}
}
我现在使用以下命令运行服务器:
I now run the server with:
bokeh serve bokehserver.py --port 5100 --host 127.0.0.1:80
现在我再也没有得到404了,但是当我访问website.com:5100/bokehserver/时却收到了"403:Forbidden".并在bokehserver终端上显示以下消息:
Now I don't get the 404 any more, but a "403: Forbidden" when I go to website.com:5100/bokehserver/. And this message on in the bokehserver terminal:
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
来解决白名单问题,但是不走运.
I tried to fix the whitelist problem by adding allow 127.0.0.1:5100
in the p-website.conf, no luck.
推荐答案
我知道了,显然您需要在Bokeh命令中添加具有相同位置的--prefix =:
I figured it out, apparently you need to add --prefix= with same location to the Bokeh command:
bokeh serve bokehserver.py --port 5100 --prefix=/plot/ --host website.com:80
p-website.conf中的位置块如下所示:
And the location block in p-website.conf will look like:
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;
}
这篇关于散景服务器+使用Nginx进行反向代理可提供404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!