sudo apt install python3 python3-pip nginx
source environment_name/bin/activate # use name created above "environment_name"
pip install django pip install gunicorn // or directly install both pip install django gunicorn
django-admin startproject myproject # use any name "myproject"
nano gunicorn_conf.py # use any name but using same better "gunicorn_conf.py"
import multiprocessing bind = '127.0.0.1:8000' # Django running port/link workers = multiprocessing.cpu_count() * 2 + 1
cd myproject # navigate to Django Project "myproject"
gunicorn myapp.wsgi:application -c ../gunicorn_conf.py # here myapp is myproject # here "myapp" is a Django project name, and at last gunicorn_conf.py is a gunicorn configuration file which created above/before.
code- oss # to open vs code from terminal
# example code ALLOWED_HOSTS = ['localhost', '0.0.0.0', '127.0.0.1'] # use IP address here
ifconfig
sudo nano /etc/nginx/sites-available/myapp # use any name "myapp" # better use vs code instead of nano sudo code- oss /etc/nginx/sites-available/myapp # check code-oss
server { listen 80; server_name your_domain.com; # Replace with your domain or IP address # example for aboveline: server_name 'ipaddress' 'another domain' ; location / { proxy_pass http://127.0.0.1:8000; # Gunicorn's default address proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled # change "myapp" to nginx config file name used above
sudo nginx -t
sudo systemctl restart nginx
sudo apt install ufw
sudo ufw allow 'Nginx Full'
sudo systemctl start nginx
gunicorn myapp.wsgi:application -c ../gunicorn_conf.py # in above code "myapp" is a Django project name # last gunicorn_conf.py is a gunicorn configuration file name
sudo systemctl stop nginx
문의 DM - 트위터(X)
메일 문의 - sanya.san@myyahoo.com
위 내용은 Gunicorn과 Nginx를 사용하여 확장 가능한 Django 애플리케이션 구축의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!