Note: Deploy Python App on Runcloud
Create new web application on runcloud server that you work on
Create a directory inside the web application or anywhere (just remember it)
Upload all your python file to the directory you just created above
Now – Install into the VPS server to install python and other staff for this example we will need
Python3
Fastapi
haversine
uvicorn
After install it, you will need to run the uvicorn but you need to run via the
Supervisor
To use supervisor
as a process manager you should either:
- Hand over the socket to uvicorn using its file descriptor, which supervisor always makes available as
, and which must be set in the
fcgi-program
section. - Or use a UNIX domain socket for each
uvicorn
process.
A simple supervisor configuration might look something like this:
Create a program name any name DIGITALXXXX.conf inside the supervisor.d
Use the config below and save
[supervisord]
[fcgi-program:uvicorn]
directory = /home/digital/
socket=tcp://127.0.0.1:3500
command=uvicorn --fd 0 mainapi:app
numprocs=4
process_name=uvicorn-%(process_num)d
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
autostart=true
autorestart=true
Then run with supervisord -n
Now go back to runcloud to go to nginx config file. I create serverblock.conf in the location.http
app-address.location.http.serverblock.conf
server {
listen 0.0.0.0:80;
server_name xxxxxxxxxxxxx.loca.la;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:3500/;
proxy_redirect off;
}
}
Now the domain xxxxxx.loca.la instead going to the main HTML folder, it will use proxy to go to the uvicorn server that I am running via 127.0.0.1:3500
Note:
To check if your app is running by checking
ps -fA | grep python
Then you can use command Kill to kill the process and restart them if needed