A typical request gets processed like this:
request -> Nginx reverse proxy -> AWS EC2 -> express api/fastapi -> response
but my biggest confusion is why a fastapi absolutely NEEDS Nginx to work, but an Express API doesn't (despite nodejs and python both having the http module and hence able to make web servers). Why do I need Nginx at all for fastapi? Can't an AWS EC2 instance act as a web server like Nginx?
This post says it's so we can hide the port number in the url, but this being the only reason seems silly to me.
CodePudding user response:
Why is a web server (i.e Nginx) REQUIRED for FastApis
Nginx is not required for FastApi. You can listen on external ports and handle requests without a reverse proxy. Even their docs include setting up Nginx under the Advanced section (Ref)
This post says it's so we can hide the port number in the url, but this being the only reason seems silly to me.
You can still hide the port number in the url if you run the Express app with sudo and listen on port 80 or 443.
Can't an AWS EC2 instance act as a web server like Nginx?
Yes it can.
There are benefits of using a proxy server like Nginx. Proxy servers can handle load balancing, caching, SSL termination and they can handle large number of concurrent connections efficiently.
Using a proxy server is a best practice. However, it is not a requirement for FastAPI or Express.