Static in Production for fastapi. #221
-
Hi, So i am temporarily using sqladmin in my fast API application in production, but the static portion of the application is not working in production unlike in development (local computer). How can I fix this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 15 replies
-
Hey, |
Beta Was this translation helpful? Give feedback.
-
The probable reason is that the static is connected via http, and your site is opened via https. |
Beta Was this translation helpful? Give feedback.
-
What if there is no proxy server in between the client and the application? My login form and all of the statics in general do not work in production because of the issue that @philipokiokio described. I am using uvicorn via a dockerfile: |
Beta Was this translation helpful? Give feedback.
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"]
containshttps
and the app will generate a static url based on scheme.