uWSGI是一個Web服務器,它實現了WSGI協議、uwsgi、http等協議。Nginx中HttpUwsgiModule的做用是與uWSGI服務器進行交換。WSGI是一種Web服務器網關接口。它是一個Web服務器(如nginx,uWSGI等服務器)與web應用(如用Flask框架寫的程序)通訊的一種規範。css
Nginx (engine x) 是一個高性能的HTTP和反向代理服務,也是一個IMAP/POP3/SMTP服務。Nginx是由伊戈爾·賽索耶夫爲俄羅斯訪問量第二的Rambler.ru站點(俄文:Рамблер)開發的,第一個公開版本0.1.0發佈於2004年10月4日。html
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"] # python3 #return ["Hello World"] # python2
uwsgi
-
-
http :
8000
-
-
wsgi
-
file
test.py,使用該命令啓動測試文件test.py,而後訪問8000端口,看是否成功。
前端
[uwsgi]
#http是項目啓動端口 #http = :9200
#socket是於=與nginx通訊的端口
socket = 127.0.0.1:8001 #the local unix socket file than commnuincate to Nginx #socket = 0.0.0.0:8001 # the base directory (full path)項目目錄 chdir = /projects/bishe # Django's wsgi file wsgi-file = bishe/wsgi.py # maximum number of worker processes(進程數) processes = 4 #thread numbers startched in each worker process(線程數) threads = 4
#這是python虛擬環境的位置 pythonpath=/root/#ROOT/.virtualenvs/vueshop/lib/python3.5/site-packages
#緩衝大小 buffer-size=65535 #monitor uwsgi status
#這是靜態文件
static-map=/static=static #stats = 127.0.0.1:9200 # clear environment on exit vacuum = true #daemonize = shops/uwsgi.log
能夠很容易看出啓動了四個進程和對應的進程號vue
2.3這時查看端口8001就能夠訪問了。python
我建立了一個my.conf,配置以下:nginx
#監聽的端口號 listen 9200; server_name 127.0.0.1; charset UTF-8; #nginx日誌位置 access_log /var/log/nginx/my_web_access.log; error_log /var/log/nginx/my_web_error.log; client_max_body_size 75M; location / { include uwsgi_params;
#這個很重要,是uwsgi的通訊端口,即socket,而不是http uwsgi_pass 127.0.0.1:8001; uwsgi_read_timeout 2; } #靜態文件 location /static { expires 30d; autoindex on; add_header Cache-Control private; alias /projects/bishe/static/; } #前端頁面 location ~\.html$ { root /var/mytest/index/; index index.html index.htm; } #前端js,css,jpg,png等路徑,能夠和drf的靜態文件一塊兒配置,防止先後臺有一個找不到 location ~.*\.(js|css|jpg|png)$ { root /var/mytest/; }
重啓nginx便可,記得uwsgi和nginx中的配置文件通訊端口要一致web
固然測試的界面依舊如上(這裏提一下,靜態文件可能找不到,須要在設置中配置(STATIC_ROOT="路徑")python manage.py collectstatic生成靜態文件)django
REST_FRAMEWORK = {json
'DEFAULT_RENDERER_CLASSES':服務器
( 'rest_framework.renderers.JSONRenderer', ),
}