CORS error, deploy in Docker and behind Apache proxy

Hello guys !

I have issues with running jupyterhub in Docker behind a proxy. I originally post it in github and people told me to post it here, as it more related to support than bug.

More specifically : I can’t create a file from the jupyter notebook (spawn by jupyterhub).

The error in the UI

The error in the console

[W 2020-11-19 20:49:22.157 SingleUserNotebookApp handlers:390] Blocking Cross Origin API request for /jhub/user/etienne/api/contents.  Origin: https://DOMAIN-NAME, Host: localhost:8000
[W 2020-11-19 20:49:22.158 SingleUserNotebookApp handlers:613] Not Found
[W 2020-11-19 20:49:22.159 SingleUserNotebookApp log:181] 404 POST /jhub/user/etienne/api/contents (etienne@::ffff:172.17.0.1) 3.19ms

The same problem arise when I create a fake notebook.ipynb (using echo): the kernel won’t start (since it is launched from the same POST request on /api/sessions I guess)

My setup

docker run -p 8000:8000 jupyterhub/jupyterhub jupyterhub --url='http://:8000/jhub/' --NotebookApp.allow_origin='*' --NotebookApp.token='' --debug

  • Apache used as reverse proxy config with the following config :
<VirtualHost *:80>
  ServerName DOMAIN-NAME
</VirtualHost>

 # For JupyterHub
 RewriteRule /jhub/(.*) ws://localhost:8000/jhub/$1 [P,L]
 RewriteRule /jhub/(.*) http://localhost:8000/jhub/$1 [P,L]
 ProxyPass /jhub/ http://localhost:8000/jhub/
 ProxyPassReverse /jhub/ http://localhost:8000/jhub/


<VirtualHost *:443>
  ServerName DOMAIN-NAME

  # Jupyterhub
  RewriteEngine On
  RewriteCond %{HTTP:Connection} Upgrade [NC]
  RewriteCond %{HTTP:Upgrade} websocket [NC]
  RewriteRule /(.*) ws://127.0.0.1:8000/$1 [P,L]

  <Location "/jhub/">
    ProxyPreserveHost on
    ProxyPass         http://127.0.0.1:8000/jhub/
    ProxyPassReverse  http://127.0.0.1:8000/jhub/
  </Location>
</VirtualHost>

Also, not shown here but i tried to ass Header set Access-Control-Allow-Origin "DOMAIN-NAME" at various location of my apache config without any success.

The config seems okay since it works on another VM of the same subnet but with JupyterHub installed manually (i.e not deployed using Docker).

The OS and the packages version

  • OS: Ubuntu 18.04.3 LTS
  • notebook version : 6.1.5 (installed using pip since not contains in the docker image)
  • jupyterhub version : 1.2.1.

Would you guys have any ideas on this issue ? Thanks :slight_smile:

Issue was found (see https://github.com/jupyterhub/jupyterhub/issues/3268):

The default site /etc/apache2/sites-available/000-default-le-ssl.conf (added by certbot --apache I think) was enabled and had the same ServerName as the config I’ve shown in the issue, which was creating conflict.

After disabling the website (or changing the servername) the CORS issue disappears.

1 Like