Django+nginx+uwsgi+dwebsocket 启动方法

Posted helloord

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django+nginx+uwsgi+dwebsocket 启动方法相关的知识,希望对你有一定的参考价值。

Django+nginx+uwsgi+dwebsocket 启动方法

收集静态文件

opesn@opesn:~$ cat /app/cmdb/cmdb/settings/dev.py 
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), ‘static‘)

#然后执行收集命令
python3 manage.py collectstatic

安装uwsgi模块

pip3 install uwsgi

#如果安装不上使用编译安装
tar xf uwsgi-latest.tar.gz
cd uwsgi-2.0.18/
sudo python3 uwsgiconfig.py --build
sudo python3 setup.py install

用uwsgi 启动django的dwebsocket需要加格外参数

opesn@opesn:~$ cat /app/cmdb/cmdb/settings/dev.py 
WEBSOCKET_FACTORY_CLASS = ‘dwebsocket.backends.uwsgi.factory.uWsgiWebSocketFactory‘

启动uwsgi模块

uwsgi --http 192.168.10.20:8000 --chdir /app/cmdb --wsgi-file cmdb/wsgi.py --http-websockets --http-timeout 300 --async 30 --ugreen

配置nginx

opesn@opesn:/server/tools/uwsgi-2.0.18$ cat /etc/nginx/conf.d/default.conf 
server{
    listen  80;
    charset utf-8;
    server_name www.opesn.com;

     location /  {
        proxy_pass http://192.168.10.20:8000;
        proxy_set_header Host $host;
        proxy_http_version 1.1; 
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout 60;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
     }

        location /static/ {
            alias /app/cmdb/static/;
        }
}

配置systemd启动uwsgi

opesn@opesn:~$ cat /etc/systemd/system/kkbuluo_cmdb.service 
[Unit]
Description=HTTP Interface Server
After=syslog.target

[Service]
KillSignal=SIGQUIT
User=www
Group=www
ExecStart=/usr/local/bin/uwsgi --http 192.168.10.20:8000 --chdir /app/cmdb --wsgi-file cmdb/wsgi.py --logto /app/cmdb/logs/uwsgi.log --master --processes 2 --threads 1 --http-websockets --async 30 --ugreen --http-timeout 300
Restart=always
Type=notify
NotifyAccess=all
StandardError=syslog

[Install]
WantedBy=multi-user.target

以上是关于Django+nginx+uwsgi+dwebsocket 启动方法的主要内容,如果未能解决你的问题,请参考以下文章

通过 Nginx 的 uwsgi + django - uwsgi 设置/生成?

转载nginx+uwsgi+django

Django+Nginx+uWSGI = 504 网关超时

uWSGI + Nginx + Django 部署

Django + Uwsgi + Nginx 实现生产环境部署

Django + Uwsgi + Nginx 实现生产环境部署