Open utterances-bot opened 1 year ago
Very good documentation, I appreciate it! Just in case anyone was wondering,
$ sudo supervisorctl restart fastapi-app
will RESTART the app after you edit code.
how to reload when using gunicorn with Uvicorn process
@airanirenuka, you can use sudo supervisorctl restart fastapi-app
.
can gunicorn load balancing with multiple gpus? any advices for delopying a python server(load several deep models) with multiple gpus?
Sorry, but I haven't done that myself. For more complex apps, I separate the app and inference logic into different services, and use something like torchserve
Hi
I was wondering whether this would work with APIKeys (access_tokens in header)?
@Muntasir2001 I don't see why not!
There is one important thing missing: you should disable the default nginx site, otherwise it won't work (at least not with a domain name in my case):
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl reload nginx
Nice guide! Before getting all the way to the bottom of it and noticing that you have this all in a repo, I used it to create a project that includes an install script for ease of use. It assumes you've installed the prerequisites on your own, but then the rest of the install is free from interaction. Feel free to fork it if you find it useful, I linked to an archived copy of this page in the install script to give you credit. Please let me know if you would like me to change the attribution in any way.
How to attach a custom SSL certificate from Namecheap? please advice.
$sudo supervisorctl restart fastapi-app is not picking up my code changes. can anyone help?
is possible use gunicorn from system, instead from venv? I want to use uvicorn and the other deps from venv, but gunicorn i would use for other apis and the docs recommend installing it globally, because would be easier to config multiples applications, so i wanna try to do something like:
NAME=installers_tickets_backend
DIR=/home/backends/installers_tickets
USER=root
GROUP=root
WORKERS=1
WORKER_CLASS=uvicorn.workers.UvicornWorker
VENV=$DIR/venv/bin/activate
BIND=unix:$DIR/run/gunicorn.sock
LOG_LEVEL=error
cd $DIR
source $VENV
/usr/bin/gunicorn main:app \ # -> '/usr/bin/gunicorn' is the path for system gunicorn
--name $NAME \
--workers $WORKERS \
--worker-class $WORKER_CLASS \
--user=$USER \
--group=$GROUP \
--bind=$BIND \
--log-level=$LOG_LEVEL \
--log-file=-
@vittxr yes that should work
@dylancastilo but doesn't work, because i was getting "modules not found" - somehow, when i try to use absolute path, supervisor ignores venv dependencies and try to find the modules globally instead (idk)... i give up and install gunicorn inside venv xD (after wasting some hours on it). I am using debian 12 by the way
I'm trying to get websockets to work, but I just don't get it. Anyone knows, how to do that?
Hey, thanks for this awesome documentation. I spent almost 4-5 hours while solving the issue of deployment of FastAPI with nginx and I was fetching the error. but this docs save my time.
Thanks again
Hi, Can someone help? I don't see any output. no errors in log file either. Something went wrong after step5(nginx). It was working before that.
so the curl command - curl --unix-socket /home/fastapi-user/fastapi-nginx-gunicorn/run/gunicorn.sock localhost
only runs in venv. If I open a new terminal and run the above command it does not work. Any idea?
sorry 1 more update, I can see the output using - curl http://localhost, but not the IP in the browser?
@dylanjcastillo How can I configure this setup in such a manor that the supervisor runs my gunicorn workers only if my FastAPI receives traffic. And remove the workers from memory if the FastAPI is idle for say like 120 seconds. I need this for reusing my GPU memory. The workers capture my GPU and are never clearing the memory, causing trouble for my other processes as they are unable to allocate GPU memory.
So, I want the gunicorn to be running only when the request for my fastAPI is hit and if not the fastapi should not be in memory.
How to Securely Deploy a FastAPI app with NGINX and Gunicorn
In this tutorial, you'll learn how to use NGINX, and Gunicorn+Uvicorn to deploy a FastAPI app, and generate a free SSL certificate for it.
https://dylancastillo.co/fastapi-nginx-gunicorn/