index











zhaoyatao.com

go to bottom

django + gunicorn + nginx, server setup note




















Django | server setup
# source
https://www.youtube.com/watch?v=YnrgBeIRtvo&ab_channel=DotJA







# prepare knowledge

# kill a port:8000 lsof -i:8000 kill -9 "your port's pid wants to be killed" # kill a process:nginx ps kill -9 "your nginx's pid wants to be killed"

# install nginx & requirements

apt install nginx apt install python3-venv python3 -m venv django_env source django_env/bin/activate pip list pip install django pip install gunicorn

# start with setting Django

django-admin startproject myproject cd myproject/ pwd # /root/myproject mkdir static cd static pwd # /root/myproject/static nano myproject/setting.py # STATIC_URL = '/root/myproject/static/' nano myproject/myproject/settings.py # allowed host = ['xxx.xxx.xxx.xxx']

# edit this to setup gunicorn

cd myproject/ # where the manage.py is here pwd # /root/myproject nano gunicorn_config.py #### command = '/root/django_env/bin/gunicorn' pythonpath = '/root/myproject' bind = 'xxx.xxx.xxx.xxx:8000' workers = 3 #### gunicorn -c gunicorn_config.py myproject.wsgi Ctrl + Z bg

# setup nginx

service nginx start nano /etc/nginx/sites-available/myproject #### server { listen 80; server_name xxx.xxx.xxx.xxx; location /static/ { root /root/myproject/static/; } location / { proxy_pass http://xxx.xxx.xxx.xxx:8000; } } #### cd /etc/nginx/sites-enabled ln -s /etc/nginx/sites-available/myproject systemctl restart nginx # make sure this foler: /etc/nginx/sites-enabled # only have 2 more link # open a brower, type in xxx.xxx.xxx.xxx done 221125 * 230108 update some chapters





back to top