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

How to handle app mounts #2

Open
jd-solanki opened this issue Sep 8, 2021 · 5 comments
Open

How to handle app mounts #2

jd-solanki opened this issue Sep 8, 2021 · 5 comments

Comments

@jd-solanki
Copy link

Hello,

Thanks so much for this repo. I learned a lot from your sample repo. I successfully deployed app to subpath and I am also able to view docs and openapi.json at desired subpath.

The problem I am facing is I am unable to view media (user uploads) files. I mounted them using app.mount()

settings is pydantic's BaseSettings instance

app = FastAPI(
    openapi_url=settings.OPEN_API_URL,
    docs_url="/docs" if settings.ENVIRONMENT == EnumEnvironment.DEVELOPMENT else "/secret-docs-path",
    root_path=settings.ROOT_PATH,
)

media_path = str(Path(settings.ROOT_PATH) / "media") if settings.ROOT_PATH else "/media"
app.mount(media_path, StaticFiles(directory=settings.MEDIA_DIR), name="media")

With the above app configuration, I visit user-uploaded media files via domain domain.com/my/sub/path/media/2021/9/logo.png I don't see file. But I try using port domain.com:8000/my/sub/path/media/2021/9/logo.png I get to see the file.

Do you know what's going on?

Thanks so much for sharing this repo. Without your custom worker solution, I don't know how much it will take to deploy the app.

Regards.

@jd-solanki jd-solanki changed the title How to handle media How to handle app mounts Sep 8, 2021
@Midnighter
Copy link
Owner

Since it works when you specify the port explicitly, I wonder if it is rather a problem with your proxy configuration? Is that possible?

@jd-solanki
Copy link
Author

I guess it has to do with server configuration but I was inspired by yours. Below is my server config:

 location /tools {
    rewrite ^/tools(.*)$ $1 break;
    include proxy_params;
    proxy_pass https://xxx.xxx.xxx.xxx:5000;
}

The app is running under port 5000 using --bind. In the first reply, I wrote 8000 as that it common port.

I admit that my server has other stuff going on including wordpress site at the root.

Another weird thing I am facing is If I visit pdf file then I get nginx's 404 and If I try to visit png file I uploaded for testing then I get fastapi's 404 {"detail":"Not Found"}.

I just really don't know why I am unable to see files. Even I don't know what's the issue and where should I look for it.

Regards.

@Midnighter
Copy link
Owner

In the first reply, I wrote 8000 as that it common port.

What do you mean by common port? Common between what?

Another weird thing I am facing is If I visit pdf file then I get nginx's 404 and If I try to visit png file I uploaded for testing then I get fastapi's 404 {"detail":"Not Found"}.

That probably has to do with the default mimetypes configured on nginx.

Could there be an issue with how the locations are defined in the nginx configuration? The order of definition matters for path matching.

@jd-solanki
Copy link
Author

Sorry for being late.

"Common Port" means usually app runs on 8000 if we don't specify a port for our app.

Do you have any guide where I can learn nginx configuration?

@Midnighter
Copy link
Owner

Sorry, I don't know of a tutorial that I can recommend. Many guides do exist, though.

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

No branches or pull requests

2 participants