Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Running with NGINX is now possible.
Running with NGINX
NGINX is a high-performance web server, known for its stability, rich feature set, simple configuration, and low resource consumption. NGINX acts as a reverse proxy, that is, it receives client requests, forwards them to the FastAPI server (running via Uvicorn or Gunicorn), and then passes the responses back to the clients.
To run with NGINX, you start by uncommenting the following part in your
docker-compose.yml
:Which should be changed to:
Then comment the following part:
Which becomes:
Then pick the way you want to run (uvicorn or gunicorn managing uvicorn workers) in
Dockerfile
.The one you want should be uncommented, comment the other one.
1. One Server
If you want to run with one server only, your setup should be ready. Just make sure the only part that is not a comment in
deafult.conf
is:2. Multiple Servers
NGINX can distribute incoming network traffic across multiple servers, improving the efficiency and capacity utilization of your application.
To run with multiple servers, just comment the
Running With One Server
part indefault.conf
and Uncomment the other one:Warning
Note that we are using
fastapi1:8000
andfastapi2:8000
as examples, you should replace it with the actual name of your service and the port it's running on.