in a recent article,
https://www.vultr.com/docs/how-to-deploy-fastapi-applications-with-gunicorn-and-nginx-on-ubuntu-20-04/
I read that fastapi "can work with WSGI if needed". I was wondering how?
I did a whole project with fastapi and tried to deploy it on cpanel shared hosting(my option for the moment) ,
in the wsgi.py file I used a2sg library
from main import app
from a2wsgi import ASGIMiddleware
application = ASGIMiddleware(app)
but I get 503 temporary busy, try again when I browse to the page
so, how can I deploy my app , I deployed django with ease but fasapi is an issue as it mainly uses ASGI.
is it also possible?
2
Answers
There are few checks you need to do apart from adding the A2WSGI Middleware.
Adding empty py files named as
__init__.py
in each directory including root of applicationCreate new
passenger.py
file with same code you have given inwsgi.py
Use the above
passenger.py
file while setting up the python application, also keepwsgi.py
as you have prepared already in same directory.(Cpanel->Setup Python App)
Run
Uvicorn
server with unused port like60323
etc.Restart the app from the Python Application Options
I have created this simple repository on github to show how to run under Apachepython a basic webapp based on ASGI (with fastapi) using a WSGI server: danielemaddaluno/pyjel
This is the project:
The
wsgi.py
file:The
app.py
file:The
requirements.txt
file:The
setup.sh
file: