How to reverse proxy to a location other than root?

#1
by lint - opened

Hey thanks for the config, it works great!

But now I want to reverse proxy so that localhost:80/mypath goes to localhost:7860/mypath, where my gradio app is running
(I added an additional main route to my gradio app so that the index page can be accessed at both http://localhost:7860 and http://localhost:7860/mypath).

The gradio app at localhost:80/mypath shows up as a blank page (I can tell its the gradio app if I inspect html). The gradio apps at http://localhost:7860 and http://localhost:7860/mypath work correctly

How can I make this work? my server block looks like this

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name _;

    location /mypath {
        # Serve GRADIO 7860
        proxy_pass http://localhost:7860;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_cache_bypass $http_upgrade;
        proxy_read_timeout 86400;
        proxy_redirect off;
    }
}

hi @lint , sorry for the delay, let me understand, do you want you Gradio app to run on /mypath right? so you might not need a reverse proxy, do you have other app running in parallel?
If not, you can follow this recipe to mount Gradio on a different route https://gradio.app/sharing-your-app/#mounting-within-another-fastapi-app

Thanks radames! I did end up using the solution you linked by mounting gradio apps on the fastapi instance.

I wanted to try running gradio apps on separate uvicorn servers from the fastapi instance so that I could embed the gradio apps as web components instead of just iframes. I found that when mounting gradio apps on the fastapi instance, they cannot be embedded as web components on the same fastapi instance (the embedded component shows as always loading).

I wanted to use a nginx reverse proxy to expose these independent gradio apps on my domain. Ultimately I found there were also other technical issues (i.e. user authentication) with this approach that were beyond my capabilities, so I just took the simple solution of mounting the gradio apps and embedding them as iframes in my other webpages.

lint changed discussion status to closed

interesting problem @lint , I'm glad you've found a solution.

Sign up or log in to comment