1. 不使用ini配置文件,直接命令行啟動
首先進入網站的根目錄,這里假設我的項目是在/home/mysite
cd /home/mysite //進入根目錄
/python37/bin/uwsgi --http :8000 --file app/wsgi.py --static-map=/static=static //啟動web服務,qpp為一個目錄,wsgi.py文件放在里面。
2.使用ini配置文件啟動uWSGI
寫一個ini配置文件,名稱自定義,我這定義一個wsgi.ini的配置文件,此文件放在項目的根目錄下(在我的項目中放在/home/mysite目錄下),即跟manage.py放一個目錄下。
配置好了進入web根目錄啟動 ./python37/bin/uwsgi --ini ./uwsgi.ini
uwsig內容如何:
[uwsgi]
http=0.0.0.0:8000
socket=app.sock
master=true
#我的項目DjangoLi放在此目錄下
chdir = /home/cc/
#DjangoLi是我的項目目錄名
wsgi-file = DjangoLi/wsgi.py
# maximum number of worker processes
processes=4
threads=2
# Django's wsgi file
#下面這句是舊版的需要配,我用的是最新的所以注釋了
#module=DjangoLicense.wsgi:application
# chmod-socket=664
# uid=www-data
# gid=www-data
# clear environment on exit
vacuum = true
注意:這樣配置后,用/uwsgi --ini ./uwsgi.ini啟動正常django,但是頁面是沒法出來的,會提示 Resource interpreted as Stylesheet but transferred with MIME type text/plain 還有js錯誤之類的
解決辦法:
urls.py加入:
from django.views.static import serve
from DjangoLicense.settings import STATIC_ROOT
urlpatterns = [
# url(r'e/', views.hello),
url(r'^static/(?P<path>.*)$', serve, {'document_root': STATIC_ROOT}),
]
在settings.py中加入
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
然后啟動后就正常了