File tree 1 file changed +69
-0
lines changed 1 file changed +69
-0
lines changed Original file line number Diff line number Diff line change
1
+ sudo apt update
2
+ sudo apt install python3-venv python3-dev libpq-dev nginx curl -y
3
+
4
+ python3.12 -m venv venv
5
+ source venv/bin/activate
6
+ pip install -r requirements.txt
7
+ uvicorn main:app --reload
8
+ nano .env
9
+
10
+ sudo ufw allow 8000
11
+
12
+
13
+ pip install gunicorn
14
+ gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --bind 0.0.0.0:8000
15
+
16
+ sudo nano /etc/nginx/sites-available/fastapi_project
17
+
18
+ server {
19
+ listen 80;
20
+ server_name url;
21
+
22
+ location / {
23
+ proxy_pass http://127.0.0.1:8000;
24
+ proxy_set_header Host $host;
25
+ proxy_set_header X-Real-IP $remote_addr;
26
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
27
+ proxy_set_header X-Forwarded-Proto $scheme;
28
+ }
29
+ }
30
+
31
+ sudo ln -s /etc/nginx/sites-available/fastapi_project /etc/nginx/sites-enabled/
32
+ sudo systemctl restart nginx
33
+
34
+
35
+ sudo nano /etc/systemd/system/fastapi_project.service
36
+
37
+ [Unit]
38
+ Description=Gunicorn instance to serve FastAPI Project
39
+ After=network.target
40
+
41
+ [Service]
42
+ User=
43
+ Group=
44
+ WorkingDirectory=/home/ubuntu/
45
+ ExecStart=/home/ubuntu/venv/bin/gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --bind 127.0.0.1:8000
46
+
47
+ [Install]
48
+ WantedBy=multi-user.target
49
+
50
+
51
+
52
+ sudo systemctl start fastapi_project
53
+ sudo systemctl enable fastapi_project
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
You can’t perform that action at this time.
0 commit comments