反向代理多个 ipython 个笔记本服务器
reverse proxy mulitple ipython notebook servers
目前我们运行正在 nginx 代理后面安装一个 Ipython 笔记本服务器。这很有效,因为它是一个简单的 1 对 1 映射。
现在我们想要 运行 在 1 个代理后面增加多个笔记本服务器。由于这些服务器将被动态添加,代理也应该是动态的。
理想情况下,我想在 url 子路径上代理:
http://open.net/py1 -> http://secure1:8888
http://open.net/py2 -> http://secure2:8888
http://open.net/py3 -> http://secure3:8888
etc.
这种方法的问题是 Ipython 没有在它的 html 中使用相对 url。摘录:
<script src="/static/.../promise.min.js"</script>
<script src="/static/.../require.js"</script>
<script> ...
所以里面 http://open.net/py2 require.js
将通过 http://open.net/static/.../require.js
加载,这当然会导致 502。它应该是 http://open.net/py2/static/.../require.js
问题:解决这个问题的好策略是什么?
约束:
- 无法触及来源html
- 我不能为每个 Ipython 服务器使用子域(因为它们是动态添加的)
what's a good strategy to solve this?
子域
I cannot use subdomains for each Ipython server (as they are dynamically added)
不正确。
# this will only py<some-digits> subdomain.
server {
listen 80;
server_name ~^(?<sub>py\d+)\.example\.com$;
# now you have $sub variable that contains subdomain
# and could be used to choose what server you want to connect
...
}
# catch all server block that simple shows 404 for any request
server {
listen 80 default_server;
return 404;
}
目前我们运行正在 nginx 代理后面安装一个 Ipython 笔记本服务器。这很有效,因为它是一个简单的 1 对 1 映射。
现在我们想要 运行 在 1 个代理后面增加多个笔记本服务器。由于这些服务器将被动态添加,代理也应该是动态的。
理想情况下,我想在 url 子路径上代理:
http://open.net/py1 -> http://secure1:8888
http://open.net/py2 -> http://secure2:8888
http://open.net/py3 -> http://secure3:8888
etc.
这种方法的问题是 Ipython 没有在它的 html 中使用相对 url。摘录:
<script src="/static/.../promise.min.js"</script>
<script src="/static/.../require.js"</script>
<script> ...
所以里面 http://open.net/py2 require.js
将通过 http://open.net/static/.../require.js
加载,这当然会导致 502。它应该是 http://open.net/py2/static/.../require.js
问题:解决这个问题的好策略是什么?
约束:
- 无法触及来源html
- 我不能为每个 Ipython 服务器使用子域(因为它们是动态添加的)
what's a good strategy to solve this?
子域
I cannot use subdomains for each Ipython server (as they are dynamically added)
不正确。
# this will only py<some-digits> subdomain.
server {
listen 80;
server_name ~^(?<sub>py\d+)\.example\.com$;
# now you have $sub variable that contains subdomain
# and could be used to choose what server you want to connect
...
}
# catch all server block that simple shows 404 for any request
server {
listen 80 default_server;
return 404;
}