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

Set root correctly for Gradio apps that are deployed behind reverse proxies #7411

Merged
merged 29 commits into from Feb 14, 2024

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Feb 13, 2024

This PR fixes the issues that we're seeing around the root url when Gradio apps are deployed behind nginx or other reverse proxies. As far as I can tell, there were two separate issues:

  1. The root_path parameter in Blocks was being ignored. This parameter is needed to tell Gradio (FastAPI really) the subpath where the Gradio app is being served from. E.g. if you are serving Gradio on www.mydomain.com/demo, it should be /demo. Now, its correctly accounted for. While its hard to write an end-to-end test for this, I have added unit tests for get_root_url() and I have tested it by running an nginx reverse proxy on an ec2 instance here: http://35.85.61.147/gradio-demo/

Main:

image

This PR:

image
  1. When serving behind an nginx proxy, the "x-forwarded-proto" is supposed to designate whether the original website is being served on https or on http. We use this to set http/https in the root in the config. However, sometimes this header is not set correctly, or it fails to contain the protocol information. This causes a problem on websites that are using https because we try to fetch certain gradio static assets on http, which browsers automatically block. I added another check in the frontend to check to see if current window is being served with https and if so, upgrade the config.root to be https as well

Closes: #7391 (as confirmed by @pseudotensor)
Closes: #7317

(May close?) #6920

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 13, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/335daba3999f0c478ae2d62cfa051be8a170476d/gradio-4.18.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@335daba3999f0c478ae2d62cfa051be8a170476d#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 13, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/client patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Set root correctly for Gradio apps that are deployed behind reverse proxies

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs abidlabs marked this pull request as ready for review February 13, 2024 23:08
@abidlabs abidlabs marked this pull request as draft February 13, 2024 23:08
@abidlabs abidlabs changed the title [WIP] Set root path correctly Set root correctly for Gradio apps that are deployed behind reverse proxies Feb 14, 2024
@abidlabs abidlabs marked this pull request as ready for review February 14, 2024 02:02
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix @abidlabs !

js/app/src/Index.svelte Outdated Show resolved Hide resolved
test/test_routes.py Show resolved Hide resolved
test/test_routes.py Show resolved Hide resolved
@abidlabs
Copy link
Member Author

Thanks @freddyaboulton for the review! I'll clean this up tomorrow and merge it in.

cc @pngwn and @aliabid94 as well if y'all wanna take a look at this before that

@abidlabs abidlabs enabled auto-merge (squash) February 14, 2024 16:08
@abidlabs abidlabs merged commit 32b317f into main Feb 14, 2024
7 checks passed
@abidlabs abidlabs deleted the root-path branch February 14, 2024 16:14
@pngwn pngwn mentioned this pull request Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants