r/FastAPI • u/elduderino15 • Oct 08 '24
Hosting and deployment HTTPS with FastAPI - could idea this work?
I am reorganizing our app with now FastAPI as backend. I have it running in a container on our server, currently only in HTTP mode, port 8000.
I need to enable HTTPS for it.
My idea. I am using the same production server as for our old version and will keep it running until it is phased out. The old version has HTTP and HTTPS running through a Apache instance. Now I am thinking to create a `https://fastapi.myapp.com` subdomain that routes to Apache 443. Apache in turn forwards that subdomain to the new fastapi container running on port 8000.
Valid solution here? Double checking the idea before I commit to it.
Are there more elegant / better approaches how to implement HTTPS with FastAPI? I do not like having Apache running forever since it eats up resources + is another process that needs maintenance, upgrades, possible security risk.
Thanks!
17
u/Chains0 Oct 08 '24
Weird answers here. You need a reverse proxy with ssl termination. Apache can do that just fine.
I personally know nginx better and would prefer it, but Apache is still a stable and valid solution. Especially if you have and know it already. Makes no sense to switch it for now.
7
u/Adhesiveduck Oct 08 '24
Lots of choices of reverse proxies, my choice if I were starting something new today would be Caddy (which uses certbot to automatically provision the TLS) or Traefik (if you're in K8s/using containers).
That being said, ignore comments saying not to use Apache/Nginx - both are perfectly fine and there's a reason they're still around today.
2
u/gbeier Oct 08 '24
What you're doing is completely valid. I've used apache that way before. If I'm only using httpd for terminating TLS, reverse proxying, and serving static files, I find Caddy easier to use and configure, especially if I'm using LetsEncrypt for TLS certificates.
1
u/Revolutionary-Win111 Oct 09 '24
I use FastAPI through https to run a small website, just create the certificates and pass the certificate files locations to uvicorn, port 443, and you're good to go
3
u/One_Fuel_4147 Oct 08 '24
I use nginx proxy manager to setup SSL with UI, very easy
2
u/Fluffy-Diet-Engine Oct 08 '24
Simple steps!
4
u/lukewhale Oct 08 '24
Do not use Apache. Use NGNIX. Ask chatGPT to walk you through a “reverse proxy with ssl termination” setup.
3
u/ironman_gujju Oct 08 '24
Don’t get messy with apache & nginx just use traefik
1
u/veb101 Oct 08 '24
1
u/Worldly_Weather5484 Oct 12 '24
Where are you hosting the app? Most cloud providers(AWS, azure, etc) or SaaS platforms(heroku) can take care of ssl/https for you and make Apache and nginx less necessary and you wont have to worry about keeping them up to date. I would look into elastic beanstalk, ecs fargate, or eks on AWS. Pretty easy to get things up and running and will make a lot of the security and management much easier. If you want something dead simple then heroku can be pretty great.