前提條件:html
個人django項目名稱爲:hello,所在目錄是:/media/p1/proj/py/hello/nginx
切換工做目錄到hello項目所在目錄shell
# cd /media/p1/proj/py/hello/
啓動uwsgidjango
# uwsgi --http 127.0.0.1:8080 --file hello/wsgi.py --static-map=/static=static
或瀏覽器
# uwsgi --http :8080 --file hello/wsgi.py --static-map=/static=static
此時能夠經過訪問 http://127.0.0.1:8080/
看看是否成功。app
這一步能夠避免每一次啓動uwsgi都要指定那麼多選項。
個人配置文件建立於:/etc/uwsgi/uwsgi.ini
socket
# uwsig使用配置文件啓動 [uwsgi] # 項目目錄 chdir=/media/p1/proj/py/hello/ # 指定項目的application module=hello.wsgi:application # 指定sock的文件路徑 socket=/media/p1/proj/py/script/uwsgi.sock # 進程個數 workers=1 pidfile=/media/p1/proj/py/script/uwsgi.pid # 指定IP端口 http=127.0.0.1:9090 # 指定靜態文件 static-map=/static=/media/p1/proj/py/hello/static # 啓動uwsgi的用戶名和用戶組 uid=root gid=root # 啓用主進程 #master=true # 自動移除unix Socket和pid文件當服務中止的時候 vacuum=true # 序列化接受的內容,若是可能的話 # thunder-lock=true # 啓用線程 # enable-threads=true # 設置自中斷時間 #harakiri=30 # 設置緩衝 #post-buffering=4096 # 設置日誌目錄 daemonize=/var/log/uwsgi/uwsgi.log
server { listen 80; server_name a.test.haoxueba.net; location / { include uwsgi_params; #uwsgi_pass 127.0.0.1:9090; uwsgi_pass unix:/media/p1/proj/py/script/uwsgi.sock; #uwsgi_param UWSGI_PYHOME test.py; uwsgi_param UWSGI_SCRIPT hello.wsgi; #uwsgi_param UWSGI_CHDIR; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { } }
啓動uwsgipost
uwsgi --ini /etc/uwsgi/uwsgi.ini
ui
和剛開始啓動的方式不一樣,咱們如今指定了配置文件,就不須要再每次設置那麼多選項了。.net
更新nginx配置:nginx -s reload
或啓動nginx:nginx
在瀏覽器地址欄輸入:http://a.test.haoxueba.net
看看咱們期待的結果會不會出現?
注意:我當初作到這一步,並無成功,檢查發現uwsgi.sock文件沒有建立,原來是權限問題,我將其目錄開放了寫權限,就OK了。
設置目錄可寫:chmod +w /media/p1/proj/py/script