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

Not working behind a reverse proxy #121

Open
victor-moreno opened this issue Dec 22, 2021 · 12 comments · May be fixed by #124
Open

Not working behind a reverse proxy #121

victor-moreno opened this issue Dec 22, 2021 · 12 comments · May be fixed by #124
Labels

Comments

@victor-moreno
Copy link

victor-moreno commented Dec 22, 2021

Bug description

For some reason, with jupyterhub (v1.4.2 in docker), behind a reverse proxy, rstudio returns a malformed url, doubling the hostname separated by comma, like: "https://www.myhost.org%2C%20www.myhost.org/jupyter/user/victor/rstudio/auth-sign-in/?appUri=%2F"
The %2C%20 is ", "

In case it helps someone with the same problem, I managed to get a working version with these changes to rewrite_auth. I never got redirected to /auth-sign-in, so the elif is there to keep current version, but is not needed in my setup.

def rewrite_auth(response, request):
    '''
       As of rstudio-server 1.4ish, it would send the client to /auth-sign-in
       rather than what the client sees as the full URL followed by
       /auth-sign-in. See rstudio/rstudio#8888. We rewrite the response by
       sending the client to the right place.
    '''
    for header, v in response.headers.get_all():
        if header == "Location":
            # Visit the correct page VM 211222
            if ", " in urlparse(v).netloc:
                u = urlparse(v)
                u = u._replace(scheme='https')
                u = u._replace(netloc=u.netloc.split(",")[0])
                response.headers[header] = urlunparse(u)
            elif v.startswith("/auth-sign-in"):
                # Visit the correct page
                u = urlparse(request.uri)
                response.headers[header] = urlunparse(u._replace(path=u.path+v))
@welcome
Copy link

welcome bot commented Dec 22, 2021

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@juzdzema juzdzema linked a pull request Mar 17, 2022 that will close this issue
@juzdzema
Copy link

We encountered a similar behaviour with rstudio returning a malformed url (in our case the url gets stripped).
For example, if we expect the url https://www.myhost-proxied.comp-any.org/user/userID/auth-sign-in/?appUri=%2F
we actually get https://www.myhost/user/userID/auth-sign-in/?appUri=%2F.

We are behind a reverse proxy as well and in an Openshift context. In PR #124 we propose a general solution
that should fix all kinds of root url problems (including that of the OP).

@guimou
Copy link

guimou commented Mar 24, 2022

@juzdzema You're the real MVP! Thank you so much. I had seen this issue before as I was struggling with the same problem since a few weeks (redirected to http://jupyterhub/user/userid/...). I worked on something else, got back to it today, debugging different things and coming closer to what you did, but then had a quick check in the issues. And BAM! The solution was there. Please accept this small token of gratitude 🍻

@moschlar
Copy link

In my case, it redirects to an URI that contains a (wrong) port specification:

https://jupyterhub....:80/user/.../rstudio/auth-sign-in?appUri=%2F

@ryanlovett
Copy link
Collaborator

@moschlar I had the same issue, with jupyter-rsession-proxy v2.1.0 and jupyter-server-proxy v3.2.2, but my nginx reverse proxy was not configured like the recommendation at https://jupyterhub.readthedocs.io/en/stable/reference/config-proxy.html. After adjusting it to match the recommendation, the port addition problem went away.

@victor-moreno Regarding the rewrite, I suspect the rewriting will no longer be necessary due to changes merged for jupyter-server-proxy v3.2.2. I believe it is the hop-by-hop PR, but I haven't tested this yet. Can you please test with the latest releases of jupyter-rsession-proxy and jupyter-server-proxy? If you're still seeing the issue, can you please share your reverse proxy configuration?

@moschlar
Copy link

@ryanlovett Hm, I just double-checked it, but it doesn't seem to make a difference... However, this is a z2jh instance which uses chp between my external reverse proxy and the hub/notebook itself... Maybe I need to dig there!

@ryanlovett
Copy link
Collaborator

ryanlovett commented Sep 13, 2022

@moschlar Thanks for checking. The latest does not work on mybinder.org either. I don't know whether mybinder uses the recommended proxy configurations or not (it probably does), but I think that jupyter-rsession-proxy has to work on it regardless.

@mathematicalmichael
Copy link

In my case, it redirects to an URI that contains a (wrong) port specification:

https://jupyterhub....:80/user/.../rstudio/auth-sign-in?appUri=%2F

I'm getting the same error with that environment.

jupyter-rsession-proxy==2.1.0
jupyter-server-proxy==3.2.2

I'm running a jupyterhub and using cloudflare tunnel as my reverse proxy so I don't exactly have the luxury of configuring nginx differently (per @ryanlovett ... not sure what the "adjustment" needed to be, nor whether I can make such a change).

@ryanlovett
Copy link
Collaborator

Okay, thanks @mathematicalmichael ! Are you able to apply #134 to your environment?

@mathematicalmichael
Copy link

mathematicalmichael commented Sep 19, 2022

edits to bottom of Dockerfile:

# RUN python3 -m pip install jupyter-rsession-proxy jupyter_server_proxy
RUN python3 -m pip install git+https://github.com/ryanlovett/jupyter-rsession-proxy@95759d85e95de6cb102702762d23f74ae2d46baa

fixed it!

thank you... had a bit of a time trying to figure out what the "solution" was amongst the discussions. The fast reply was much appreciated!!!

@ryanlovett
Copy link
Collaborator

@mathematicalmichael Okay, great. That fixes it on binder as well. I'll merge soon.

@mathematicalmichael
Copy link

:shipit:

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

Successfully merging a pull request may close this issue.

6 participants