使用SSL与Daphne NGINX部署Django频道

前端之家收集整理的这篇文章主要介绍了使用SSL与Daphne NGINX部署Django频道前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个Nginx的工作配置代理到django通道的上游daphne服务器.但是,当我将我的站点移动到ssl时,我开始遇到与websocket请求有关的403错误.这是我的错误日志:

  1. None - - [24/Apr/2017:02:43:36] "WSCONNECTING /pulse_events" - -
  2. None - - [24/Apr/2017:02:43:36] "WSREJECT /pulse_events" - -
  3. 2017/04/24 02:43:37 [info] 465#465: *10 client 69.203.115.135 closed keepalive
  4. connection

并从访问日志:

  1. - - [24/Apr/2017:02:48:54 +0000] "GET /pulse_events HTTP/1.1" 403 5 "-" "-"
  2. - - [24/Apr/2017:02:49:03 +0000] "GET /pulse_state/ HTTP/2.0" 200 1376 "-" "Pulse/1 CFNetwork/811.4.18 Darwin/16.1.0"

我的Nginx配置如下:

  1. upstream pulse_web_server {
  2. server unix:/home/pulseweb/run/gunicorn.sock fail_timeout=0;
  3. }
  4. upstream pulse_web_sockets {
  5. server unix:/home/pulseweb/run/daphne.sock;
  6. }
  7. map $http_upgrade $connection_upgrade {
  8. default upgrade;
  9. '' close;
  10. }
  11. server {
  12. listen 80;
  13. server_name backend.com;
  14. return 301 https://$host$request_uri;
  15. }
  16. server {
  17. listen 443 http2 ssl;
  18. server_name backend.com;
  19. root /var/www/vhosts/backend.com;
  20. location ~ /.well-known {
  21. allow all;
  22. }
  23. include snippets/ssl-params.conf;
  24. ssl_certificate /etc/letsencrypt/live/backend.com/fullchain.pem;
  25. ssl_certificate_key /etc/letsencrypt/live/backend.com/privkey.pem;
  26. client_max_body_size 4G;
  27. access_log /var/log/Nginx/pulse-access.log;
  28. error_log /var/log/Nginx/pulse-error.log info;
  29. location /static/ {
  30. alias /var/www/vhosts/backend.com/static/;
  31. }
  32. location /pulse_events {
  33. proxy_pass http://pulse_web_sockets;
  34. proxy_http_version 1.1;
  35. proxy_set_header Upgrade $http_upgrade;
  36. proxy_set_header Connection "upgrade";
  37. }
  38. location / {
  39. proxy_redirect off;
  40. proxy_set_header X-Real-IP $remote_addr;
  41. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  42. proxy_set_header X-Forwarded-Proto $scheme;
  43. proxy_set_header Host $http_host;
  44. proxy_set_header X-Nginx-Proxy true;
  45. proxy_set_header Connection "";
  46. proxy_http_version 1.1;
  47. server_tokens off;
  48. proxy_buffering on;
  49. if (!-f $request_filename) {
  50. proxy_pass http://pulse_web_server;
  51. break;
  52. }
  53. }
  54. }

这是我的要求.txt:

  1. asgi-redis==0.14.0
  2. asgiref==0.14.0
  3. asyncio==3.4.3
  4. autobahn==0.16.0
  5. channels==0.17.2
  6. daphne==0.14.3
  7. Django==1.10
  8. django-extensions==1.7.2
  9. django-webpack-loader==0.3.3
  10. djangorestframework==3.4.4
  11. msgpack-python==0.4.8
  12. python-dateutil==2.5.3
  13. redis==2.10.5
  14. requests==2.11.0
  15. six==1.10.0
  16. Twisted==16.2.0
  17. txaio==2.5.1
  18. zope.interface==4.2.0

任何见解将不胜感激.

最佳答案
你的Nginx期望wss请求不是ws请求.

猜你在找的Nginx相关文章