본문 바로가기
여러가지/기타

[Nginx] 엔진엑스 443 포트에서 80포트로 리다이렉트 하는 방법 !! (https -> http)

by 포스트it 2023. 11. 10.
728x90
반응형

 

[Nginx] 엔진엑스 443 포트에서 80포트로 리다이렉트(redirect) 하는 방법 !! (https -> http)

보통 보안으로 인해 ssl키를 설정 후 80으로 들어오면 443으로 리다이렉트 시키는 것이 일반적인 형태입니다.

다만 저는 특정 상황에 때문에 / url로 오게 되면 80으로 리다이렉트 시켜야해서 설정해봤습니다.

 

/ root 경로로 오게 되면 80포트에 연결 된 index.html 을 보여주고,

/other_project 경로오 오게 되면 443으로 연결 된 index.html 을 보여주는 nginx 셋팅입니다.

 

redirect 사용예시
server {
        listen 80 default_server;
        listen [::]:80;
        server_name example.co.kr;
        root /home/ubuntu/test/project;
        index index.html;

        location / {
                root /home/ubuntu/test/project;
        }
}

server {
        listen 443 ssl;
        server_name example.co.kr;

        ssl_certificate /etc/nginx/ssl/example_co.kr_cert.crt;
        ssl_certificate_key /etc/nginx/ssl/example_co.kr.key;

        location / {
                return 301 http://example.co.kr$request_uri;
        }

        location /other_project {
                alias /home/ubuntu/test/other_project;
        }
}
728x90
반응형

댓글