Containers with Apache Reverse Proxy + JupyterHub

Hi,

I have a working setup for JupyterHub that runs in a container as well as another container that deploys a website using Apache. The container with the Apache website has SSL certs and uses ProxyPass and ProxyPassReverse to serve another service that runs in a third separate container.

The website’s URL is https://host-website.ca. Right now, people have access to the third service when they go to https://host-website.ca/service/, and I want JupyterHub to show up when people go to https://host-website.ca/hub/.

In the JupyterHub container, I’ve launched JupyterHub and it says that it’s now running at http://internal-jupyterhub-ip:8000/ , so I was hoping to be able to use ProxyPass and ProxyPassReverse to serve JupyterHub as well by adding these lines in my Apache conf:

ProxyPass /hub/ http://internal-jupyterhub-ip:8000/
ProxyPassReverse /hub/ http://internal-jupyterhub-ip:8000/

My JupyterHub configuration looks something like this:

c.JupyterHub.ip = 'internal-jupyterhub-ip'
c.JupyterHub.port = 8000
c.JupyterHub.hub_ip = '192.168.152.97'
c.JupyterHub.hub_connect_ip = '192.168.152.97'

When I go to https://host-website/hub/, it shows this:


and looking at the logs for JupyterHub, it appears to be stuck in some redirect loop?

Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.399 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 3.41ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.427 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 6.06ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.444 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 3.03ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.462 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.84ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.488 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.77ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.506 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.76ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.534 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.82ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.551 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.75ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.569 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.89ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.599 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.73ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.621 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.74ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.643 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.89ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.659 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.72ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.687 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.77ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.705 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.74ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.724 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.71ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.740 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.69ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.760 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.80ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.780 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.88ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.798 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.77ms
Jul 30 18:06:26 jupyterhub jupyterhub[4550]: [I 2024-07-30 18:06:26.816 JupyterHub log:192] 302 GET / -> /hub/ (@192.168.152.10) 2.73ms

Any help on this would be greatly appreciated!

I tried adding c.JupyterHub.base_url ='/jupyterhub/' to the JupyterHub configuration file, and now when I go to https://host-website.ca/hub/ it redirects me to host-website.ca/jupyterhub/hub/ and gives a 404 Not Found error.

Pretty sure this is just a problem with me not understanding how to setup the JupyterHub configuration properly, but I’m not sure what else to try (based on what I’ve seen on past JupyterHub forum posts).

Did some more digging - and solved my own problem (I guess sometimes just writing down what’s happening can help with debugging!)

I had to set the c.JupyterHub.bind_url to be https://internal-jupyterhub-ip:8000/jupyter/ and for the Apache configuration have the lines:

ProxyPass /jupyter/ http://internal-juptyerhub-ip:8000/jupyter/
ProxyPassReverse /jupyter/ http://internal-jupyterhub-ip:8000/jupyter/

and it works!

So what I did works, as in I can login and request a job through Slurm + JupyterHub, but when I try to run some code it just hangs? I tried to open a terminal and it also just is stuck loading the terminal.

There’s a lot of information online about using Apache as a reverse proxy and JupyterHub but it seems pretty old. Our Apache version is 2.4.52, and I’m not sure what’s relevant in terms of getting things to work.

If there’s anything needed (logs, config files) to help figure out why this is happening, please let me know and I’ll provide it!

I just followed the instructions Using a reverse proxy — JupyterHub documentation and it worked! Solved!

1 Like