问题描述
我假设我可以仅使用Daphne
(ASGI)和Nginx
作为我的Django应用程序的代理来运行Django Channels
应用程序.
I was under the assumption that I could run a Django Channels
app using only Daphne
(ASGI) and Nginx
as a proxy for my Django app to begin with.
该应用程序将在127.0.0.1:8001
但是,我遇到了403 Forbidden
错误.
2019/03/06 17:45:40 [error] *1 directory index of "/home/user1/app/src/app/" is forbidden
当我发表有关此事时,另一个用户提到了
And when I posted about that, another user mentioned
并建议研究fastcgi_pass
或uwsgi_pass
或Gunicorn
.
很明显,Django Channels在ASGI
上运行,我现在正在通过该请求传递所有请求(根据请求,不是传递给uWSGI
,然后传递给ASGI
.)
Obviously Django Channels runs on ASGI
and I am passing all requests through that right now (not to uWSGI
then on to ASGI
depending on the request.)
我可以仅使用Nginx
和Daphne
来提供我的Django应用程序吗? Django Channels文档似乎是这样认为的,因为他们没有提到需要Gunicorn或类似的东西.
Can I serve my Django app with only Nginx
and Daphne
? The Django Channels docs seem to think so as they don't mention needing Gunicorn or something similar.
我的nginx配置
upstream socket {
ip_hash;
server 127.0.0.1:8001 fail_timeout=0;
}
server {
listen 80;
#listen [::]:80 ipv6only=on;
server_name your.server.com;
access_log /etc/nginx/access.log;
root /var/www/html/someroot;
location / {
#autoindex on;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri =404;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header Host $http_host;
#proxy_set_header X-NginX-Proxy true;
#proxy_pass http://socket;
#proxy_redirect off;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
#proxy_redirect off;
#proxy_set_header X-Forwarded-Proto $scheme;
#proxy_cache one;
#proxy_cache_key sfs$request_uri$scheme;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/some/fullchain.pem;
# managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/some/privkey.pem;
# managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
}
}
推荐答案
是的,有可能.试试这个配置:
Yes, it's possible. Try this config:
upstream socket {
ip_hash;
server $DAPHNE_IP_ADDRESS$ fail_timeout=0;
}
server {
...
location / {
proxy_pass http://socket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
...
}
其中$ DAPHNE_IP_ADDRESS $-您的daphne IP和不带模式(127.0.0.1:8001
)的端口.
Where $DAPHNE_IP_ADDRESS$ - your daphne IP and port without schema(127.0.0.1:8001
).
这篇关于可以仅使用Nginx和Daphne来提供Django Channels应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!