nginx+uwsgi+Django配置
阿新 • • 發佈:2019-02-12
1、nginx 配置
簡單配置
# nginx 代理到 uwsgi
server {
listen 8080;
server_name localhost;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8081;
index index.html index.htm;
}
}
2、安裝測試專案HelloWorld
django-admin.py startproject HelloWorld
進入到專案根目錄執行
python manage.py migrate
python manage.py runserver 0.0.0.0:8081 (測試)
訪問 如果沒有許可權
chmod -R 777 HelloWorld
在settings.py 檔案中ALLOWED_HOSTS陣列中加入能訪問的ip
3、uwsgi配置
pidfile = /run/uwsgi/%n.pid stats = /run/uwsgi/%n.sock chmod-socket = 666 ;配置這個可以在瀏覽器直接訪問 socket = :8081 plugin = python chdir = /var/www/python/HelloWorld/ wsgi-file = /var/www/python/HelloWorld/HelloWorld/wsgi.py py-autoreload = 1 ;使程序在後臺執行,並將日誌打到指定的日誌檔案或者udp伺服器 daemonize = /var/log/uwsgi/%n_daemonize.log
4、檢測Django錯誤
在專案的根目錄下執行 ./manage.py runserver 0.0.0.0:8083 根據錯誤提示修改