1

我目前正在使用通道 2.x 部署一个 django 项目,uwgsi 用于 http 请求,daphne 用于后台任务。

Daphne 本身和 uwgsi 一样正常运行。

两者的配置如下:

location /stream {
    # daphne server running on port 8001 so we set a proxy to that url
    proxy_pass http://0.0.0.0:8001;
    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;
}

# These requests are handled by uwsgi
location / {
    include uwsgi_params;
    uwsgi_pass unix:/run/uwsgi/app/project/socket;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    # Make the following two variables accessible to the application:
    uwsgi_param SSL_CLIENT_VERIFY $ssl_client_verify;
    uwsgi_param SSL_CLIENT_RAW_CERT $ssl_client_raw_cert;
}

所有后台工作人员都以/stream 开头。所有端点都受到保护。当登录并访问/api/v1/resource等端点时,它会正确返回数据,但是当通过/stream触发任务时,我的权限被拒绝(403)。调试这种行为我得出的结论是会话在 Daphne 和 Uwsgi 之间没有持久化。

我怎样才能实现他们之间共享的会话?

4

0 回答 0