我假设我可以只使用(ASGI)运行一个Django Channels
应用程序,并作为我的 Django 应用程序的代理开始。Daphne
Nginx
该应用程序将运行Daphne
在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
当我发布有关此内容时,另一位用户提到
在您的 nginx 配置中没有将 http 请求传递给 django 应用程序的指令
并建议查看fastcgi_pass
or uwsgi_pass
or Gunicorn
。
显然 Django Channels 正在运行ASGI
,我现在正在通过它传递所有请求(而不是uWSGI
然后ASGI
取决于请求。)
我可以只用Nginx
and服务我的 Django 应用程序Daphne
吗?Django Channels 文档似乎这样认为,因为他们没有提到需要 Gunicorn 或类似的东西。
我的 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;
}
}