Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run code or open terminal in jupyter lab after set up with Apache Reverse Proxy #7966

Open
thgngu opened this issue Mar 3, 2020 · 1 comment

Comments

@thgngu
Copy link

thgngu commented Mar 3, 2020

I have my personal domain https://mydomain.com (SSL by letsencrypt enabled), in Apache config, I have http redirected to https:

<VirtualHost *:80>
        ServerName www.mydomain.com
        ServerName mydomain.com

        ServerAdmin webmaster@localhost
        Redirect / https://mydomain.com

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

I have been enabling port forwarding on my router so I can access my jupyterlab workspace at https://mydomain.com:8888/, now I don't want to port forward anymore, I want to be able to access my workspace at https://mydomain.com/lab

After many trial and errors (i'm very noob here), I ended up with the following setting:

in jupyter_notebook_config.py

c.LabApp.port = 8888
c.LabApp.ip = 'localhost'
c.LabApp.open_browser = False
c.NotebookApp.allow_password_change=False

c.LabApp.base_url = '/lab'
c.NotebookApp.allow_remote_access = True
c.NotebookApp.allow_origin = '*'

and in apache .conf

<VirtualHost *:443>
        ServerName www.mydomain.com
        ServerName mydomain.com
        SSLProxyEngine on
        SSLProxyVerify none
        SSLProxyCheckPeerCN off
        SSLProxyCheckPeerName off
        SSLProxyCheckPeerExpire off
        ProxyPreserveHost On


        ProxyRequests Off

        <Location "/lab">
                ProxyPass        http://localhost:8888/lab
                ProxyPassReverse http://localhost:8888/lab
                ProxyPassReverseCookieDomain localhost mydomain.com
                RequestHeader set Origin "http://localhost:8888"
        </Location>

        <LocationMatch "/lab/(api/kernels/[^/]+/channels|terminals/websocket)/?">
                ProxyPass ws://localhost:8888/lab/$1
                ProxyPassReverse ws://localhost:8888/lab/$1
        </LocationMatch>

        SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Now I can access https://mydomain.com/lab, I can open any notebook, but cannot run my code, when I try to run a notebook, it seems to hang, this is what it shows when i try to open a console and print

Untitled

and the terminal in jupyterlab doesn't work. This is the terminal when I open one

Untitled

This is what printed out from Jupyterlab

newterm

And when I shut down the terminal, this is what printed out

closeterm

I don't know where to find more information to debug this on my own, so sorry if this has been solved somewhere. Please point me to any resources.

I'm using Ubuntu 16.04, anaconda 4.8.2, output of conda list | grep jupyter

jupyter_client               5.3.4                    py37_0
jupyter_core                 4.6.1                    py37_0
jupyterhub                   1.0.0                    py37_0
jupyterlab                    1.2.4                      py_0    conda-forge
jupyterlab_server         1.0.6                      py_0

Any help would be appreciated. Thank you

@thgngu thgngu changed the title Terminal in jupyter lab not working after set up with Apache ReverseProxy Cannot run code or open terminal in jupyter lab after set up with Apache Reverse Proxy Mar 3, 2020
@jbarbero
Copy link

jbarbero commented May 21, 2020

I was able to get this proxying in Apache working with the following config:

ProxyVia On
<Location "/jupyterlab">
ProxyPass http://localhost:9999/jupyterlab
ProxyPassReverse http://localhost:9999/jupyterlab
</Location>
<Location "/jupyterlab/api/kernels/">
ProxyPass ws://localhost:9999/jupyterlab/api/kernels/
ProxyPassReverse ws://localhost:9999/jupyterlab/api/kernels/
</Location>
<Location "/jupyterlab/terminals/websocket">
ProxyPass ws://localhost:9999/jupyterlab/terminals/websocket
ProxyPassReverse ws://localhost:9999/jupyterlab/terminals/websocket
</Location>

The slashes are very important. For example, leaving the ending slash off /api/kernels/ breaks it, because you need HTTP proxying up /api/kernels and then WebSockets from /api/kernels/... on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants