nginx 서버에 SSL 인증서를 설치한 후 내 노드 애플리케이션에 로그인할 수 없습니다.

nginx 서버에 SSL 인증서를 설치한 후 내 노드 애플리케이션에 로그인할 수 없습니다.

Nginx http 웹 서버에 프런트 엔드가 배포되고 AWS ec2 Linux VM의 노드 서버에 백엔드(분자 마이크로 서비스)가 배포된 노드 애플리케이션이 있습니다. 응용 프로그램 URL은 본질적으로 Linux 서버 호스트 이름 또는 공용 ipv4 주소(http://hostname:80 또는 http://ipv4:8080 )입니다. 이제 이 URL은 안전하지 않기 때문에 SSL을 사용하여 보안을 유지하려고 생각했습니다. 이를 위해 cloudns.net에서 도메인 이름을 구입하고 이를 다시 EC2 인스턴스의 퍼블릭 IPv4로 지정했습니다. 이제 certbot 및 letsencrpt.org를 사용하여 Nginx 서버에 SSL 인증서를 설치했으며 이제 로그인 페이지에 https가 있고 SSL 인증서가 올바르게 표시됩니다(https://host.mypurchaseddomainname). 이제 자격 증명을 전달하여 애플리케이션에 로그인하려고 하면 들어갈 수 없으며 검사 요소를 사용하여 확인할 때(크롬을 사용하고 있음) 요청 URL은 아무것도 반환하지 않으며 오류는 ERR_CONNECTION_CLOSED입니다. 이 요청 URL은 8082 포트에서 요청을 보내는 게시 방법입니다. 요청 URL은 다음과 같습니다: https://hostname:8082/v1/auth/signin 여기서 언급할 또 다른 사항은 SSL을 설치하기 전에 애플리케이션의 엔드포인트 URL에 포트 번호 80, 8080을 추가할 수 있으며 입력 시 결국 호스트 이름(http://hostname/signin?)이 되지만 SSL 설치 후 https URL(예: https://mypurchasedhostname:8080)에 무엇이든 추가하면 오류가 발생합니다. 도달했고 이는 로그인 요청 URL에서도 동일한 일이 발생하는 것으로 보입니다. http://hostname으로 제공되면 이러한 포트(80,8080)는 결국 https://hostname/somewelcometext가 되고 로그인 페이지가 열립니다.

서버 구성 문제인지 아니면 백엔드에서도 뭔가 변경이 필요한지 잘 모르겠습니다. 내 로그인 요청 URL에는 이전에 http가 있었는데 혼합 콘텐츠 오류를 방지하기 위해 백엔드에서 https로 변경했습니다. 아래는nginx.confSSL 구성을 추가하기 전과 후의 파일입니다.

SSL 없음:

sudo vim /etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

  #Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

     server {
        listen       80 default_server;
        listen       8080 default_server;
        server_name  mypurchasedhostname;
        root         /usr/share/nginx/html;
        index        index.html;



        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            try_files $uri $uri/ /index.html;
            add_header Cache-Control 'no-cache';
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }}

SSL 사용:

sudo vim /etc/nginx/nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

    # Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

     server {
        listen       80 default_server;
        listen       8080 default_server;
        server_name  mypurchasedhostname;
       # root         /usr/share/nginx/html;
       # index        index.html;
       return 301 https://$host$request_uri;

    }


#SSL settings

server {

    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name  mypurchasedhostname;
    root         /usr/share/nginx/html;
    index        index.html;

    ssl_certificate /etc/letsencrypt/live/mypurchasedhostname/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mypurchasedhostname/privkey.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;  # about 40000 sessions
    ssl_session_tickets off;

    # curl https://ssl-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
    # ssl_dhparam /path/to/dhparam;

    # intermediate configuration
    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    ssl_prefer_server_ciphers on;

    # HSTS (ngx_http_headers_module is required) (63072000 seconds)
    add_header Strict-Transport-Security "max-age=63072000" always;

    # OCSP stapling
    ssl_stapling on;
    ssl_stapling_verify on;

    # verify chain of trust of OCSP response using Root CA and Intermediate certs
    # ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;

    # replace with the IP address of your resolver
    resolver 8.8.8.8;
    # Load configuration files for the default server block.

        include /etc/nginx/default.d/*.conf;

        location / {
            try_files $uri $uri/ /index.html;
            add_header Cache-Control 'no-cache';
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

}

}

관련 정보