首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当对Django的请求作出反应时,就会发生net::ERR_SSL_PROTOCOL_ERROR

当对Django的请求作出反应时,就会发生net::ERR_SSL_PROTOCOL_ERROR
EN

Stack Overflow用户
提问于 2020-09-08 09:27:57
回答 1查看 963关注 0票数 2

堆栈: AWS Lightsail,React,DRF,Django,Gunicorn,NGINX

我使用加密方法创建了证书。

※我跟踪了这个网站:

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

因此,我可以无错误地访问https://mydomain

但是,当React调用Django时,就会发生net::ERR_SSL_PROTOCOL_ERROR。

我想我需要在DRF设置一些东西,Django。

在syslog和/var/log/nginx/error.log中没有记录错误。

我在谷歌上搜索但找不到我想要的东西。

我能征求意见吗?谢谢。

编辑:下面是NGINX的conf文件。

代码语言:javascript
复制
server {
    listen 80;
    server_name mydomain;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name mydomain;

    ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location / {
        root /react_project_path/build;
        index index.html index.htm;
        try_files $uri $uri/ /index.html;
    }
}

server {
    listen 8000;
    server_name mydomain;

    charset utf-8;

    location / {
        include proxy_params;
        proxy_pass https://unix:/django_project_path/gunicorn.sock;
    }

    location /static/ {
        alias /django_project_path/static/;
    }

    location /media/ {
        alias /django_project_path/media/;
    }
}

编辑:netstat结果。

编辑:现在我检查我的日志。

我刚加了一行代码。

代码语言:javascript
复制
server {
    listen 443 ssl http2;
    server_name mydomain;

    error_log /var/log/nginx/error.log debug;

    ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by Certbot
    ...

下面是NGINX的error.log。(我在这里为私有编辑了路径、令牌和会话。)

代码语言:javascript
复制
2020/09/09 15:46:29 [debug] 3322#3322: accept on 0.0.0.0:443, ready: 0
2020/09/09 15:46:29 [debug] 3322#3322: posix_memalign: 0000556469DEEA20:512 @16
2020/09/09 15:46:29 [debug] 3322#3322: *13 accept: 218.235.196.18:8093 fd:3
2020/09/09 15:46:29 [debug] 3322#3322: *13 event timer add: 3: 60000:23210254
2020/09/09 15:46:29 [debug] 3322#3322: *13 reusable connection: 1
2020/09/09 15:46:29 [debug] 3322#3322: *13 epoll add event: fd:3 op:1 ev:80002001
2020/09/09 15:46:29 [debug] 3322#3322: *13 http check ssl handshake
2020/09/09 15:46:29 [debug] 3322#3322: *13 http recv(): 1
2020/09/09 15:46:29 [debug] 3322#3322: *13 https ssl handshake: 0x16
2020/09/09 15:46:29 [debug] 3322#3322: *13 tcp_nodelay
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL ALPN supported by client: h2
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL ALPN supported by client: http/1.1
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL ALPN selected: http/1.1
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL_do_handshake: -1
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL_get_error: 2
2020/09/09 15:46:29 [debug] 3322#3322: *13 reusable connection: 0
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL handshake handler: 0
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL_do_handshake: 1
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL: TLSv1.2, cipher: "ECDHE-RSA-CHACHA20-POLY1305 TLSv1.2 Kx=ECDH Au=RSA Enc=CHACHA20/POLY1305(256) Mac=AEAD"
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL reused session
2020/09/09 15:46:29 [debug] 3322#3322: *13 reusable connection: 1
2020/09/09 15:46:29 [debug] 3322#3322: *13 http wait request handler
2020/09/09 15:46:29 [debug] 3322#3322: *13 malloc: 0000556469DF3390:1024
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL_read: -1
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL_get_error: 2
2020/09/09 15:46:29 [debug] 3322#3322: *13 free: 0000556469DF3390
2020/09/09 15:46:29 [debug] 3322#3322: *13 http wait request handler
2020/09/09 15:46:29 [debug] 3322#3322: *13 malloc: 0000556469DF3390:1024
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL_read: 813
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL_read: -1
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL_get_error: 2
2020/09/09 15:46:29 [debug] 3322#3322: *13 reusable connection: 0
2020/09/09 15:46:29 [debug] 3322#3322: *13 posix_memalign: 0000556469E3DC90:4096 @16
2020/09/09 15:46:29 [debug] 3322#3322: *13 http process request line
2020/09/09 15:46:29 [debug] 3322#3322: *13 http request line: "GET /character/ironclad HTTP/1.1"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http uri: "/character/ironclad"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http args: ""
2020/09/09 15:46:29 [debug] 3322#3322: *13 http exten: ""
2020/09/09 15:46:29 [debug] 3322#3322: *13 posix_memalign: 0000556469EAAA50:4096 @16
2020/09/09 15:46:29 [debug] 3322#3322: *13 http process request header line
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Host: mydomain"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Connection: keep-alive"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Upgrade-Insecure-Requests: 1"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Sec-Fetch-Site: same-origin"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Sec-Fetch-Mode: navigate"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Sec-Fetch-User: ?1"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Sec-Fetch-Dest: document"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Referer: https://mydomain/"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Accept-Encoding: gzip, deflate, br"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "Cookie: csrftoken=some_data; sessionid=some_data"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "If-None-Match: W/"5f577837-8e2""
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header: "If-Modified-Since: Tue, 08 Sep 2020 12:25:27 GMT"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http header done
2020/09/09 15:46:29 [debug] 3322#3322: *13 event timer del: 3: 23210254
2020/09/09 15:46:29 [debug] 3322#3322: *13 generic phase: 0
2020/09/09 15:46:29 [debug] 3322#3322: *13 rewrite phase: 1
2020/09/09 15:46:29 [debug] 3322#3322: *13 test location: "/"
2020/09/09 15:46:29 [debug] 3322#3322: *13 using configuration "/"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http cl:-1 max:1048576
2020/09/09 15:46:29 [debug] 3322#3322: *13 rewrite phase: 3
2020/09/09 15:46:29 [debug] 3322#3322: *13 post rewrite phase: 4
2020/09/09 15:46:29 [debug] 3322#3322: *13 generic phase: 5
2020/09/09 15:46:29 [debug] 3322#3322: *13 generic phase: 6
2020/09/09 15:46:29 [debug] 3322#3322: *13 generic phase: 7
2020/09/09 15:46:29 [debug] 3322#3322: *13 access phase: 8
2020/09/09 15:46:29 [debug] 3322#3322: *13 access phase: 9
2020/09/09 15:46:29 [debug] 3322#3322: *13 access phase: 10
2020/09/09 15:46:29 [debug] 3322#3322: *13 post access phase: 11
2020/09/09 15:46:29 [debug] 3322#3322: *13 generic phase: 12
2020/09/09 15:46:29 [debug] 3322#3322: *13 try files handler
2020/09/09 15:46:29 [debug] 3322#3322: *13 http script var: "/character/ironclad"
2020/09/09 15:46:29 [debug] 3322#3322: *13 trying to use file: "/character/ironclad" "/react_project_path/build/character/ironclad"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http script var: "/character/ironclad"
2020/09/09 15:46:29 [debug] 3322#3322: *13 trying to use dir: "/character/ironclad" "/react_project_path/build/character/ironclad"
2020/09/09 15:46:29 [debug] 3322#3322: *13 trying to use file: "/index.html" "/react_project_path/build/index.html"
2020/09/09 15:46:29 [debug] 3322#3322: *13 internal redirect: "/index.html?"
2020/09/09 15:46:29 [debug] 3322#3322: *13 rewrite phase: 1
2020/09/09 15:46:29 [debug] 3322#3322: *13 test location: "/"
2020/09/09 15:46:29 [debug] 3322#3322: *13 using configuration "/"
2020/09/09 15:46:29 [debug] 3322#3322: *13 http cl:-1 max:1048576
2020/09/09 15:46:29 [debug] 3322#3322: *13 rewrite phase: 3
2020/09/09 15:46:29 [debug] 3322#3322: *13 post rewrite phase: 4
2020/09/09 15:46:29 [debug] 3322#3322: *13 generic phase: 5
2020/09/09 15:46:29 [debug] 3322#3322: *13 generic phase: 6
2020/09/09 15:46:29 [debug] 3322#3322: *13 generic phase: 7
2020/09/09 15:46:29 [debug] 3322#3322: *13 access phase: 8
2020/09/09 15:46:29 [debug] 3322#3322: *13 access phase: 9
2020/09/09 15:46:29 [debug] 3322#3322: *13 access phase: 10
2020/09/09 15:46:29 [debug] 3322#3322: *13 post access phase: 11
2020/09/09 15:46:29 [debug] 3322#3322: *13 generic phase: 12
2020/09/09 15:46:29 [debug] 3322#3322: *13 try files handler
2020/09/09 15:46:29 [debug] 3322#3322: *13 http script var: "/index.html"
2020/09/09 15:46:29 [debug] 3322#3322: *13 trying to use file: "/index.html" "/react_project_path/build/index.html"
2020/09/09 15:46:29 [debug] 3322#3322: *13 try file uri: "/index.html"
2020/09/09 15:46:29 [debug] 3322#3322: *13 generic phase: 13
2020/09/09 15:46:29 [debug] 3322#3322: *13 content phase: 14
2020/09/09 15:46:29 [debug] 3322#3322: *13 content phase: 15
2020/09/09 15:46:29 [debug] 3322#3322: *13 content phase: 16
2020/09/09 15:46:29 [debug] 3322#3322: *13 content phase: 17
2020/09/09 15:46:29 [debug] 3322#3322: *13 content phase: 18
2020/09/09 15:46:29 [debug] 3322#3322: *13 http filename: "/react_project_path/build/index.html"
2020/09/09 15:46:29 [debug] 3322#3322: *13 add cleanup: 0000556469E3EB80
2020/09/09 15:46:29 [debug] 3322#3322: *13 http static fd: 14
2020/09/09 15:46:29 [debug] 3322#3322: *13 http set discard body
2020/09/09 15:46:29 [debug] 3322#3322: *13 http ims:1599567927 lm:1599567927
2020/09/09 15:46:29 [debug] 3322#3322: *13 http im:"W/"5f577837-8e2"" etag:"5f577837-8e2"
2020/09/09 15:46:29 [debug] 3322#3322: *13 xslt filter header
2020/09/09 15:46:29 [debug] 3322#3322: *13 HTTP/1.1 304 Not Modified
2020/09/09 15:46:29 [debug] 3322#3322: *13 write new buf t:1 f:0 0000556469EAAF10, pos 0000556469EAAF10, size: 189 file: 0, size: 0
2020/09/09 15:46:29 [debug] 3322#3322: *13 http write filter: l:1 f:0 s:189
2020/09/09 15:46:29 [debug] 3322#3322: *13 http write filter limit 0
2020/09/09 15:46:29 [debug] 3322#3322: *13 posix_memalign: 0000556469EAC6D0:512 @16
2020/09/09 15:46:29 [debug] 3322#3322: *13 malloc: 0000556469EB15C0:16384
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL buf copy: 189
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL to write: 189
2020/09/09 15:46:29 [debug] 3322#3322: *13 SSL_write: 189
2020/09/09 15:46:29 [debug] 3322#3322: *13 http write filter 0000000000000000
2020/09/09 15:46:29 [debug] 3322#3322: *13 http finalize request: 0, "/index.html?" a:1, c:2
2020/09/09 15:46:29 [debug] 3322#3322: *13 http request count:2 blk:0
2020/09/09 15:46:29 [debug] 3322#3322: *13 http finalize request: -4, "/index.html?" a:1, c:1
2020/09/09 15:46:29 [debug] 3322#3322: *13 set http keepalive handler
2020/09/09 15:46:29 [debug] 3322#3322: *13 http close request
2020/09/09 15:46:29 [debug] 3322#3322: *13 http log handler
2020/09/09 15:46:29 [debug] 3322#3322: *13 run cleanup: 0000556469E3EB80
2020/09/09 15:46:29 [debug] 3322#3322: *13 file cleanup: fd:14
2020/09/09 15:46:29 [debug] 3322#3322: *13 free: 0000556469E3DC90, unused: 0
2020/09/09 15:46:29 [debug] 3322#3322: *13 free: 0000556469EAAA50, unused: 2427
2020/09/09 15:46:29 [debug] 3322#3322: *13 free: 0000556469DF3390
2020/09/09 15:46:29 [debug] 3322#3322: *13 hc free: 0000000000000000
2020/09/09 15:46:29 [debug] 3322#3322: *13 hc busy: 0000000000000000 0
2020/09/09 15:46:29 [debug] 3322#3322: *13 free: 0000556469EB15C0
2020/09/09 15:46:29 [debug] 3322#3322: *13 reusable connection: 1
2020/09/09 15:46:29 [debug] 3322#3322: *13 event timer add: 3: 65000:23215262

在这个时候,

我认为流量没有到达Django甚至GUnicorn,并且似乎被NGINX中的SSL错误所阻塞。

但我仍然认为我没有足够的信息来找出错误的原因。

请给我一个建议,谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-10 02:44:10

解决方案非常简单,只需在侦听8000之后添加'ssl‘即可。

代码语言:javascript
复制
...
server {
    listen 8000 ssl;
    server_name mydomain;

    ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    charset utf-8;

    location / {
        include proxy_params;
        proxy_pass https://unix:/django_project_path/gunicorn.sock;
    }

    location /static/ {
        alias /django_project_path/static/;
    }

    location /media/ {
        alias /django_project_path/media/;
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63791004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档