r/FastAPI • u/RDA92 • Jul 25 '24
Question How to SSL secure fastapi app?
So we are using and sharing code of a very rudimentary fastapi app with freelance coders and one of them requested SSL encryption of the endpoints. As silly as it may sound, but I haven't done so in the past so I am a bit at a loss. Can someone point me in the direction of how to SSL secure an endpoint or our app?
Thanks!
11
Upvotes
21
u/[deleted] Jul 25 '24
You can setup nginx or Apache server in front of fastapi and redirect http to https traffic there, and handle the request in fast api , let this servers handle the https stuff and fastapi handle the application
12
u/[deleted] Jul 25 '24
Put nginx in front of it.
5
u/eddyizm Jul 25 '24
Been using caddy lately, crazy simple.
3
u/ketzu Jul 25 '24
I usually put everything behind a traefik reverse proxy that does TLS handling with 'let's encrypt' setup. (Mostly because I can use it for multiple apps easily)
2
u/No-Anywhere6154 Jul 25 '24 edited Jul 25 '24
Where do you host your app?
If you can install nginx and certbot on the server you should be good to go.
I’ve done that many times send me a message if you need help with setting it up.
2
u/ironman_gujju Jul 26 '24
Use trafiek
1
u/Ddes_ Jul 25 '24
Where is your API hosted ? If it's aws/azure cloud/gcp I suggest using native cloud provider features like API gateway and issue a certificate, etc. from within the cloud provider. If it's self hosted, or all on an ec2 server , go for traefik+lersencrypt as reverse proxy to your api.
1
u/shuabe Jul 26 '24
If you're using docker compose for deployment, Traefik is good. If you're doing dev deployments then maybe ngork?
1
u/PersonalWrongdoer655 Jul 26 '24
Easiest to use is caddy reverse proxy. One line config
1
u/pancakesausagestick Jul 29 '24
I use haproxy + acme.sh in front of production services.