Proxying web server that serves static pages using Jupyter server proxy

I know this is a old issue but I am facing a very similar situation with a web server that serves static files. So, I have a web server, say myapp , that I would like to proxy using Jupyter server proxy. I have integrated it into JupyterLab and I can access it at http://localhost:8888/myapp URL. The landing page of myapp has say following content:

<H2>Create new session:</H2>
<FORM action="/session/new.cgi" METHOD=POST>

that serves static files. When I click submit on the page, I am being redirected to http://localhost:8888/session/new.cgi and end up with 404 error. If I manually navigate to http://localhost:8888/myapp/session/new.cgi I can access the page without any issues. I have tried using absolute_url , rewrite_response without much luck. Is it possible to achieve what I am trying here? If so, any pointers would be appreciated!


This is an absolute path, so it will always take you to /session. You could try changing it to a relative path (remove the leading /), but without seeing your whole setup it’s impossible to say whether this will fix it. You’ve mentioned your app is serving static files but new.cgi implies it’s a CGI app, so it depends on whether the application requires knowledge of the base prefix or not.

Thanks a lot for coming back @manics. Well, it is a 3rd party application which we cannot really modify. It is actually a web interface for doing atomistic simulations. We are trying to integrate it into JupyterLab using server proxy. I figured out that /session is like an absolute path and that is where we are having issues with integrating it with proxy server. It is indeed a CGI app running some Perl scripts in the backend.

Is there any way we can make this work without having to change the paths in the web server? Thanks!!

You could write your own jupyter-server-proxy extension that modifies the HTML content returned to the client, see for example

(that example modifies the headers instead of the HTML).

Are you sure there’s no way to configure the base path for the application, not even at startup?

1 Like

I have looked into sources and no, I did not find any way to configure the base path. It is a very basic web app. Thanks for the pointer about rewrite_response. I did look into that example as well but did not think about rewriting HTML content. I will give it a try. If I find a solution, I will post here.

Thanks again for your help!!


Hello @manics,
I could make it work using rewrite_response by rewriting the HTML content. What I did is basically injecting base tag into HTML head section and changing all absolute URLs to relative. It might not be the most elegant solution but it does the job. I am not sure if I can post it here (in case others face similar issue) as this web app I am working with is not open source.

Thanks again for this pointer. This rewrite_response seems to be quite nice and powerful feature!!

1 Like