작업실

Nginx에서 모든 요청을 https non-www로 돌리는 방법 두번째

컨텐츠 정보

본문

한달 전 쯤에 링크1에 올린 글처럼 작성했었습니다.

 

링크2에서 더 좋아보이는(?) 듯한 방법이 있어, 현재 제 홈페이지도 이렇게 적용했습니다.

 

 

1. HTTPS + non-www

 

server {

    listen 80;

    server_name wsgvet.com www.wsgvet.com;

    location / {

        rewrite       ^/(.*)$ https://wsgvet.com/$1 permanent;

    }

}

 

server {

listen 443 ssl http2;

server_name wsgvet.com www.wsgvet.com;

...

if ($host != 'wsgvet.com' ) {

        rewrite          ^/(.*)$  https://wsgvet.com/$1 permanent;

    }

...

}

 

2. HTTPS + www

 

server {

    listen 80;

    server_name www.wsgvet.com wsgvet.com;

    location / {

        rewrite       ^/(.*)$ https://www.wsgvet.com/$1 permanent;

    }

}    

 

server {

listen 443 ssl http2;

server_name www.wsgvet.com wsgvet.com;

...

if ($host != 'www.wsgvet.com' ) {

        rewrite          ^/(.*)$  https://www.wsgvet.com/$1 permanent;

    }

...

}

 

 

3. 결론

 

성능에는 별 차이없는 것 같습니다만, 예전에는 두번 거쳐서 넘어가는 느낌이라면 

 

지금은 단 한번의 리라이트로 넘어가기 때문에 더 나은 것 같습니다.

 

적극 추천드립니다.

관련자료

댓글 0
등록된 댓글이 없습니다.
전체 157 / 4 페이지
RSS

최근글


새댓글


알림 0