安裝 uwsgiphp
sudo
pip
install
uwsgi --upgrade
css
使用 uwsgi 運行項目html
uwsgi --http :8001 --chdir
/path/to/project
--module project.wsgi
nginx
這樣就能夠跑了,project.wsgi 指的是 project/wsgi.py 文件bash
這樣只是測試,正式環境下:app
先編寫uwsgi.ini文件:socket
[uwsgi] chdir=/home/soms # Django項目根目錄 (絕對路徑) module=soms.wsgi:application master=True # process-related settings # master pidfile=/home/soms/vm.pid vacuum=True # clear environment on exit max-requests=1000 daemonize=/home/soms/v_uwsgi.log socket = 0.0.0.0:10000 #真實服務的端口 #http = 0.0.0.0:9090
其中soms 改成只能項目名字就行。#是註釋掉的,這裏保留作學習助於理解。學習
啓動:uwsgi --ini uwsgi.ini
測試
啓動成功後uwsgi會佔用10000端口運行該項目,但要注意這裏沒配http,因此不能直接用http訪問。spa
安裝nginx
而後添加配置文件:
server
{
listen 9090; server_name mytest.com; index index.html; location / { root /home/soms; uwsgi_pass 127.0.0.1:10000; include uwsgi_params; uwsgi_param UWSGI_CHDIR /home/soms; uwsgi_param UWSGI_SCRIPT wsgi; } location ~ .*\.(log|php|pl|py|sh|cgi)$ { return 403; } location /static/ { root /home/soms; access_log off; } location ~ .*\.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) { root /home/soms; expires 30d; } location ~ .*\.(js|css)?(.*) { root /home/soms; expires 12h; } }