ubuntu使用uwsgi+nginx部署django
阿新 • • 發佈:2018-11-30
ls -lha
export WORKON_HOME=~/venv
source /usr/local/bin/vitualenvwrapper.sh
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
安裝python3
apt-get update sudo apt-get install python3-dev build-essential libssl-dev libffi-dev libxml2 libxml2-dev libxslt1-dev zlib1g-dev sudo apt-get install python3 sudo apt-get install python3-pip
1.什麼是伺服器?
啟用虛擬環境:
sudo pip3 install virtualenv
sudo pip3 install virtualenvwrapper
source bin/activate
pip3 install django==1.11.6
django-admin startproject smartkidz
python3 manage.py startapp api
關閉虛擬環境:
deactivate
pip freeze pip freeze > req.txt pip3 install -r req.txt sudo apt-get install libmysqlclient-dev pip install mysqlclient
安裝資料庫
sudo apt-get install mysql-server
進入資料庫建立自己的賬戶並給分配所有的許可權,並且重新整理許可權,在配置檔案當中bind 0.0.0.0
python3 manage.py runserver
部署上線uwsgi的安裝及測試
安裝uwsgi pip3 install uwsgi -i https://pypi.douban.com/simple/ 測試 uwsgi --http :8000 --module GuLiEdu.wsgi 安裝配置nginx sudo apt-get install nginx smartkidz_nginx.conf # the upstream component nginx needs to connect to upstream django { # server uninx:///path/to/your/mysite/mysite.sock; # for a file socket server 127.0.0.1:8000; # for a web port socket (we'll use this first) } #configuration of the server server { #the port your site will be served on listen 80; #the domain name it will serve for server_name 47.106.224.45; charset utf8; #max upload size client_max_body_size 75M; location /static { alias /home/smartkidz/smartkidz/static; } location /{ uwsgi_pass django; include /etc/nginx/uwsgi_params; } } 將該配置檔案加入到nginx的啟動配置資料夾中 sudo cp smrtkidz_nginx.conf /etc/nginx/conf.d/ python3 manage.py collectstatic sudo service nginx restart ps -aux|grep nginx # ite_uwsgi.ini file [uwsgi] # Django-related settings # the base directory (full path) chdir = /home/python/smartkidz/ # Django's wsgi file module = smartkidz.wsgi # the virtualenv(full path) # process-related settings #master master = true process = 10 socket = 127.0.0.1:8000 vacuum = true virtualenv = /home/venv logto = /tmp/mylog.log uwsgi -d -i uwsgi.ini sudo netstat -antup sudo kill 7358