Skip to content

Static in Production for fastapi. #221

Answered by ilnuru
philipokiokio asked this question in Q&A
Discussion options

You must be logged in to vote

The probable reason is that the static is connected via http, and your site is opened via https.
To solve this, you need to make sure that your proxy server (like nginx ) is passing the necessary headers to your application. encode/starlette#538 (comment)
Next, you need to configure uvicorn. The --forwarded-allow-ips flag tells the server which ips to accept these headers from. The --proxy-headers flag will enable passing the required headers. https://www.uvicorn.org/deployment/
Now inside your fastapi or starlette app scope["scheme"] contains https and the app will generate a static url based on scheme.

Replies: 3 comments 15 replies

Comment options

You must be logged in to vote
10 replies
@ilnuru
Comment options

@ilnuru
Comment options

@ilnuru
Comment options

@ilnuru
Comment options

@aminalaee
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by aminalaee
Comment options

You must be logged in to vote
5 replies
@aminalaee
Comment options

@stefanosmav
Comment options

@aminalaee
Comment options

@stefanosmav
Comment options

@aminalaee
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants