본문 바로가기
Nginx

[Nginx] Nginx https 적용

by 승븐지 2025. 7. 10.
반응형
기존 http로 설정을했던 nginx 웹존 http로 설정을했던 nginx 웹서버를 https로 바꾸는 과정이다 .

 

1. 서비스를 킨 후 작동중이던 nginx 웹서버를 중지 시킨다. cmd로 해도된다 

 

2. nginx.conf 경로에 들어가서 nginx.conf 파일을 연다 .

 

3.여기서 https 를 적용해야하니 https를 위해 발급 받은 key를 해당 경로에 넣어준다 경로가없으면 폴더를 우선 생성을 해주자 

4. 2번에서 기존 conf 파일에 설정을 확인 후 3번에서 만든 경로와 파일명들을 추가해준다 
코드로 보여주겠다. 
기존 http 소스 
##################################
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       3000;
        server_name  elo.eloko.co.kr;

        location / {
            root   html;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;  # React Router를 사용하는 경우에 추가
        }

        location /api/ {
            proxy_pass http://elo.eloko.co.kr:9090;  # 스프링 부트 서버의 주소와 포트
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }

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


#############변경되는 소스 
###https 적용
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       443 ssl;
        server_name  elo.eloko.co.kr;

        # SSL 인증서 설정
         ssl_certificate      D:/Project_Src/was/nginx-1.24.0/cert/Wildcard.eloko.co.kr_pem.pem;
         ssl_certificate_key  D:/Project_Src/was/nginx-1.24.0/cert/KeyFile_Wildcard.eloko.co.kr_pem.key;

        location / {
            root   html;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;  # React Router를 사용하는 경우에 추가
        }

        location /api/ {
            proxy_pass http://elo.eloko.co.kr:9090;  # 스프링 부트 서버의 주소와 포트
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
5.저장한 후 다시 Nginx 서비스 시작

 

6.이후 http 로 되어있던 웹 페이지에 접속 후 https 적용 확인. 

 

반응형

'Nginx' 카테고리의 다른 글

[Nginx] Windows 환경 Jenkins https 적용  (0) 2025.07.16