日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Django +nginx + uwsgi + daphne部署

發布時間:2025/3/15 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Django +nginx + uwsgi + daphne部署 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Django 項目用 channels 寫了一個實時聊天室(用websocket) 。uwsgi對websocket不太友好。所以http的使用uwsgi,websocket使用Daphne 。

nginx 配置
upstream django {server unix:///var/www/wenzhou/xzykdx/xzykdx.sock; # for a file socket# server 127.0.0.1:8001; # for a web port socket (we'll use this first) }upstream daphne {server unix:///var/www/wenzhou/xzykdx/daphne.sock; # for a file socket# server 127.0.0.1:8001; # for a web port socket (we'll use this first) }server {listen 8000;server_name wenzhou;charset utf-8;client_max_body_size 75M;autoindex_localtime on;location /static {alias /var/www/wenzhou/xzykdx/static;autoindex_localtime on; }location / {include /var/www/wenzhou/xzykdx/uwsgi_params;uwsgi_pass django;#try_files $uri @proxy_to_app;autoindex_localtime on; }location /ws/ {proxy_pass http://daphne;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_redirect off;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Host $server_name;}}

uwsgi配置

[uwsgi] socket = /var/www/wenzhou/xzykdx/xzykdx.sock chdir = /var/www/wenzhou/xzykdx module = xzykdx.wsgi master = true #socket-websockets = true #http-websockets = true processes = 2 threads = 4 plugin = python3 buffer-size = 32768 enable-threads = true max-requests = 2000 chmod-socket = 666 uid=1000 gid=1000 harakiri = 60 #vacuum = true daemonize = /var/log/uwsgi.log #pidfile = /var/run/uwsgi.pid

daphne配置

#/asgi.py (django3.x自帶的有這個文件 修改下就可以) import os import django from channels.routing import get_default_applicationos.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") django.setup() application = get_default_application()

注意要在項目根目錄運行命令
daphne 在安裝channels時已經安裝了

daphne -u /var/www/wenzhou/xzykdx/daphne.sock xzykdx.asgi:application

可以寫個腳本 開機啟動

# asgi.sh cd /var/www/wenzhou/xzykdx /var/www/wenzhou/xzykdx/wxykdx/bin/daphne -u /var/www/wenzhou/xzykdx/daphne.sock xzykdx.asgi:application

uwsgi官網
Channels官網
Daphne官網

總結

以上是生活随笔為你收集整理的Django +nginx + uwsgi + daphne部署的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。