EC2+nginx+django+gunicorn+letsencrypt ssl -> 시간 초과

EC2+nginx+django+gunicorn+letsencrypt ssl -> 시간 초과

나는 지금 몇 시간 동안 어려움을 겪고 있으며 SE에 대해 비슷한 질문을 많이 겪었습니다. 그러나 나는 문제를 해결할 수 없었습니다.

명백한 질문에 대답하려면 다음을 수행하십시오.

  • 실행 중인 EC2(우분투) 인스턴스에 방화벽이 없습니다.
  • 443 포트는 인/아웃바운드용으로 열려 있습니다.
  • ssl 파일은 다음과 같이 생성되었습니다.sudo certbot certonly --standalone
  • 암호화되지 않은 요청은 정상적으로 작동합니다.
  • 내 도메인의 A-레코드가 내 EC2 인스턴스의 퍼블릭 DNS를 가리키도록 설정했습니다. 하지만 네임스페이스 레코드에 대한 옵션은 없습니다.
  • 응 사실 난 바보야

다음을 추가하는 것 외에 nginx.conf 파일을 건드리지 않았습니다.

include /etc/nginx/sites-enabled/*;

/etc/nginx/sites-available/myapp.conf의 내 nginx-conf(...../sites-enabled/myapp.conf의 심볼릭 링크 포함):

server {
        listen 80;
        listen 443 default ssl;   

        ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem;

        server_name mydomain;

        location /static/ {
                autoindex on;
                alias /home/ubuntu/MYAPP/static/;
        }

        location /data/ {
                autoindex off;
                alias /home/ubuntu/MYAPP/data/;
        }

        location / {
                include proxy_params;
                proxy_pass http://unix:/home/ubuntu/MYAPP/app.sock;
        }
}

내 APPS의 settings.py에 다음을 추가했습니다.

ALLOWED_HOSTS = [
  'localhost',
  '127.0.0.1',
  'mywebsite.com']

지금은 다음 내용을 주석 처리했습니다.

#SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
#SECURE_SSL_REDIRECT = True
#SESSION_COOKIE_SECURE = True
#CSRF_COOKIE_SECURE = True

발행은 nc -vz localhost 443제공합니다Connection to localhost 443 port [tcp/https] succeeded!

netstat -ntlp준다

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      -   

그러나 curl -v localhost:443결과는

*   Trying 127.0.0.1:443...
* Connected to localhost (127.0.0.1) port 443 (#0)
> GET / HTTP/1.1
> Host: localhost:443
> User-Agent: curl/7.71.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Server: nginx/1.18.0 (Ubuntu)
< Date: Fri, 08 Jan 2021 15:14:04 GMT
< Content-Type: text/html
< Content-Length: 264
< Connection: close
< 
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>
* Closing connection 0

그리고 https://...를 통해 내 도메인에 액세스하려고 하면 시간 초과가 발생합니다.

편집: Steffen이 지적했듯이 내 컬 명령이 잘못되었습니다. 여기가 맞습니다

curl -v https://localhost:443

발생

*   Trying 127.0.0.1:443...
* Connected to localhost (127.0.0.1) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /home/ubuntu/anaconda3/ssl/cacert.pem
  CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=mydomain.com
*  start date: Jan  8 10:37:06 2021 GMT
*  expire date: Apr  8 10:37:06 2021 GMT
*  subjectAltName does not match localhost
* SSL: no alternative certificate subject name matches target host name 'localhost'
* Closing connection 0
* TLSv1.3 (OUT), TLS alert, close notify (256):
curl: (60) SSL: no alternative certificate subject name matches target host name 'localhost'
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

이제 /var/log/nginx/error.log에는 오류가 표시되지 않습니다.

/var/log/nginx/access.log 

브라우저에서 https를 통해 열려고 하면 어떤 요청도 표시되지 않습니다. http만 사용하면 요청이 기록됩니다. 그러면 요청이 nginx에 도착하지도 않은 것 같습니다. 그렇죠?

나는 이전에 nginx(또는 서버/백엔드와 관련된 모든 것)를 사용해 본 적이 없으며 전혀 모릅니다.

편집 2: 이것이 작동하려면 탄력적 IP가 필요합니까? 어떤 제안이 있으십니까?

관련 정보