又一次在服務器部署Django,此次部署的是博客,覺得有了上次的經驗,此次會好多,結果仍是搗鼓了一陣子,仍是把整個流程都寫好吧python
用pip安裝uwsginginx
pip install uwsgi
隨後在與manage.py同一目錄下新建配置文件 uwsgi.ini服務器
[uwsgi] chdir = /usr/local/blog/mysite module = mysite.wsgi:application socket = 127.0.0.1:8000 processes = 4 threads = 2 master = true daemonize = /usr/local/blog/mysite/run.log disable-logging = true
而後啓動app
uwsgi uwsgi.ini
更多關於uwsgi可閱讀官方文檔:http://uwsgi-docs.readthedocs.io/en/latest/socket
若是對網站內容進行了修改,須要關閉uwsgi後再啓動網站
sudo killall -9 uwsgi
刪除進程後再進行啓動rest
用apt-get安裝nginxcode
apt-get install nginx
安裝完後打開/etc/nginx/sites-available/default文件,更改配置server
server { listen 80 default_server; listen [::]:80 default_server; server_name .vhyz.me; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8000; } location /static { alias /usr/local/blog/mysite/static; } }
location指與uwsgi通訊的配置,static是Django靜態文件生成目錄blog
隨後重啓
sudo service nginx restart
首先在settings.py裏設置如下內容
DEBUG = False STATIC_ROOT = os.path.join(BASE_DIR, 'statics')
而後執行
python manage.py collectstatic
這樣靜態文件由Nginx轉發,uwsgi負責與Django的通訊的配置就弄好了。