Deploy Django project with Nginx, and Gunicorn on Ubuntu 22.04 |
Автор: Official Tech
Загружено: 2023-10-11
Просмотров: 9017
Howdy Programers,
-------------------------------------------------------------
Creating systemd Socket and Service Files for Gunicorn
sudo nano /etc/systemd/system/gunicorn.socket
paste below code:
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
-------------------------------------------------------------
sudo nano /etc/systemd/system/gunicorn.service
paste below code::
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myprojectdir
ExecStart=/home/sammy/myprojectdir/myprojectenv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
myproject.wsgi:application
[Install]
WantedBy=multi-user.target
-------------------------------------------------------------
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
sudo systemctl status gunicorn.socket
-------------------------------------------------------------
Configure Nginx to Proxy Pass to Gunicorn
sudo nano /etc/nginx/sites-available/myproject
paste below code:
server {
listen 80;
server_name server_domain_or_IP;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/sammy/myprojectdir;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled
-------------------------------------------------------------
Thank you
Regards
Official Tech
--------------------------------------------------------------
Code: https://github.com/officialtech
Video: / officialtechjb
Home: https://hindbay.com
Services: https://fourthX.com
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: