我想在我的主机ubuntu虚拟机上配置nginx作为反向代理,指向运行在docker端口8888上的jupyterhub。我使用子路径,而不是子域,我的公司防火墙只允许我访问端口80和443,所有其他端口都被阻止,这就是为什么我不能使用rewrite。这可以工作,但不显示来自jupyter hub的资源(css文件、图像等)页面路径myservername.com/jphubdisplays,但资源从myservername.com加载(没有子路径/jphub)Ex(徽标从www.example.com加载myservername.com/hub/logo而不是myservername.com/jphub/hub/logo。
有人知道我这样做是否正确吗?我应该在配置中更改什么?
upstream jupyter {
server localhost:8888;
keepalive 32;
}
server {
listen 80;
server_name myservername.com;
ssl_certificate /etc/ssl/cert-request/cert.pem;
ssl_certificate_key /etc/ssl/private/cert.key;
ssl_prefer_server_ciphers on;
location /jphub/ {
proxy_pass http://jupyter/;
proxy_http_version 1.1;
proxy_redirect default;
proxy_redirect / /jphub/;
proxy_redirect http://jupyter/ https://$host/jphub/;
proxy_pass_header Set-Cookie;
proxy_pass_header Cookie;
proxy_pass_header X-Forwarded-For;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
proxy_set_header X-Nginx-Proxy true;
add_header X-Upstream $upstream_addr;
proxy_read_timeout 86400;
}
}
1条答案
按热度按时间zzwlnbp81#
当
location
路径以/
结束时,Nginx在转发请求之前删除前导部分。要让它转发完整路径,请删除尾随的
/
,这样您就有了在Nginx配置中。