耽擱了近2個月,終於解決了,主要是nginx/uwsgi/django相關的配置:html
1、django工程settings.py,添加 nginx
WEBSOCKET_FACTORY_CLASS = "dwebsocket.backends.uwsgi.factory.uWsgiWebSocketFactory"web
參考:http://www.javashuo.com/article/p-bflmgbhl-de.htmldjango
2、nginx配置後端
location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8088; uwsgi_send_timeout 600; # 指定向uWSGI傳送請求的超時時間,完成握手後向uWSGI傳送請求的超時時間。 uwsgi_connect_timeout 600; # 指定鏈接到後端uWSGI的超時時間。 uwsgi_read_timeout 600; ##### 支持websocket proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; }
3、uwsgi.ini 服務器
[uwsgi] # 配置服務器的監聽ip和端口,讓uWSGI做爲nginx的支持服務器的話,設置socke就行;若是要讓uWSGI做爲單獨的web-server,用http #http = 127.0.0.1:8088 socket = 127.0.0.1:8088 # 配置項目目錄(此處設置爲項目的根目錄) chdir = /srv/qa-platform/back-server # 配置入口模塊 (django的入口函數的模塊,即setting同級目錄下的wsgi.py) wsgi-file = back-server/wsgi.py # 開啓master, 將會多開一個管理進程, 管理其餘服務進程 master = True # 服務器開啓的進程數量 processes = 2 # 以守護進程方式提供服, 輸出信息將會打印到log中 daemonize = /srv/qa-platform/back-server/logs/wsgi.log # 服務器進程開啓的線程數量 threads = 4 # 退出的時候清空環境變量 vacuum = true # 進程pid pidfile = uwsgi.pid
4、啓動:uwsgi --ini uwsgi.ini --http-websocketswebsocket