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

Gradio mounted with fastapi via https in nginx returns wrong path #8073

Open
1 task done
aka7774 opened this issue Apr 19, 2024 · 2 comments
Open
1 task done

Gradio mounted with fastapi via https in nginx returns wrong path #8073

aka7774 opened this issue Apr 19, 2024 · 2 comments
Assignees
Labels
bug Something isn't working cloud Issues that only happen when deploying Gradio on cloud services

Comments

@aka7774
Copy link

aka7774 commented Apr 19, 2024

Describe the bug

I use https connection and BASIC authentication to securely so many ai apps.

https://fastapi.example.com:18000/gradio
is accessed by the nginx proxy to
http://127.0.0.1:8000/gradio
is called.

http://127.0.0.1:8000/
is fastapi and gradio is mounted on /gradio.

For example, a connection that should access /gradio/info becomes /info and returns a 404 error.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

nginx.conf

server {
  server_name fastapi.example.com;
  listen 18000 ssl;

  location / {
        proxy_pass http://127.0.0.1:8000/;
        proxy_buffering off;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host 'fastapi.example.com:18000';
        proxy_set_header X-Forwarded-Host 'fastapi.example.com:18000';
        proxy_set_header X-Forwarded-Proto $scheme;

        auth_basic "Basic Authentication";
        auth_basic_user_file "/etc/nginx/conf.d/.htpasswd";
  }
}

main.py

import gradio as gr
from app import demo
app = FastAPI()
...
gr.mount_gradio_app(app, demo, path="/gradio")

app.py

import gradio as gr
with gr.Blocks() as demo:
...

if __name__ == '__main__':
    demo.launch()

Temporary workaround

  location = /info {
    rewrite ^ /gradio/info;
  }
  location = /theme.css {
    rewrite ^ /gradio/theme.css;
  }
  location /assets/ {
    rewrite (.*) /gradio$1;
  }
  location /heartbeat/ {
    rewrite (.*) /gradio$1;
  }
  location /queue/ {
    rewrite (.*) /gradio$1;
  }

Screenshot

image

Logs

No response

System Info

gradio==4.27.0
fastapi==0.110.2
uvicorn==0.29.0

nginx version: nginx/1.24.0
built by gcc 11.2.0 (Ubuntu 11.2.0-19ubuntu1)
built with OpenSSL 3.0.2 15 Mar 2022

Severity

I can work around it

@aka7774 aka7774 added the bug Something isn't working label Apr 19, 2024
@abidlabs abidlabs self-assigned this Apr 21, 2024
@abidlabs
Copy link
Member

Will take a look! Thanks for providing the detailed repro

@abidlabs abidlabs added the cloud Issues that only happen when deploying Gradio on cloud services label Apr 23, 2024
@insistence
Copy link

Similar issue, after setting root_path to uvicorn, mounting the gradio app in fastapi shows 404 error. The same error still occurs when the front-end uses the Vite proxy.

from fastapi import FastAPI
import gradio as gr
import uvicorn


app = FastAPI()


def greet(name):
    return "Hello " + name + "!"


gradio_app = gr.Interface(fn=greet, inputs="text", outputs="text")

gr.mount_gradio_app(app, gradio_app, path="/gradio")


if __name__ == "__main__":
    uvicorn.run('app:app', host="0.0.0.0", port=8000, root_path='/dev-api')

I think this issue seems to be related to the bug mentioned in this PR(tiangolo/fastapi#11160).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cloud Issues that only happen when deploying Gradio on cloud services
Projects
None yet
Development

No branches or pull requests

3 participants