Nginx + uwsgi + django + websocket(dwebsocket)环境部署

Nginx + uwsgi + django + websocket(dwebsocket)环境部署

1.确保django项目能正常跑起来,websocket能调通
2.uwsgi配置

[uwsgi]
socket = 127.0.0.1:8000  
home = /data/env/chat  
chdir = /data/wwwroot/django_range/two_chat/chat 
module = chat.wsgi:application 

master = True


processes = 4
vacuum = True
enable-threads = true
daemonize = /data/wwwroot/django_range/my_uwsgi/uwsgi.log 
wsgi-file = chat/wsgi.py
pidfile = /data/wwwroot/django_range/my_uwsgi/uwsgi.pid
static-map = /media=/data/wwwroot/django_range/back/media

3.nginx配置

map $http_upgrade $connection_upgrade {
        default upgrade;
        ''   close;
}
server
                {
	
                listen                   80;
                server_name              devops.xx.com devops.xx.local;
                access_log               /export/servers/nginx/logs/devops.xx.local/devops.xx.local_access.log main;
                error_log                /export/servers/nginx/logs/devops.xx.local/devops.xx.local_error.log warn;
                error_page 400 401 402 403 404 405 408 410 412 413 414 415 500 501 502 503 506 = http://www.jd.com/error2.aspx;
					charset     utf-8;
	# #########################核心配置就这2行#########################################
      location / {
				include         /export/servers/nginx/conf/uwsgi_params;
				uwsgi_pass      unix:/export/App/DevOPS/Python_20160906/Python_20160906.sock;
        }
    #################################################################################
      location /static/ {
			alias	/export/App/DevOPS/Python_20160906/static/;
		}
	  # websocket的匹配
      location ~ /index/websocket_demo/ {
			include     uwsgi_params;
			uwsgi_pass      127.0.0.1:8000;
			proxy_redirect off;
			proxy_http_version 1.1;
		    proxy_set_header Upgrade $http_upgrade;
		    proxy_set_header Connection "upgrade";
	}
	    location = / {
			rewrite ^ /index/ permanent;
        }
	    location = /favicon.ico {
			rewrite ^ /static/image/favicon.ico permanent;
	}
		location /devops/ {
			rewrite ^/devops/(.*)$ /$1 last;
	}
        location /software/ {
			alias /export/Data/software/;
			allow all;
			autoindex on;
			autoindex_exact_size off;
			autoindex_localtime on; 
        }
}

4.uwsgi支持django后端的websocket(dwebsocket模块)
(1)修改django项目的settings.py,添加一条数据

WEBSOCKET_FACTORY_CLASS = 'dwebsocket.backends.uwsgi.factory.uWsgiWebSocketFactory'

(2)修改uwsgi的配置文件,添加异步选项

async = 30
ugreen = ''
http-timeout = 300
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值