본문 바로가기
IT Knowledge/보안

Nginx 80 redirect 443(force redirect to HTTPS)

by Seok. 2022. 1. 7.
반응형

Nginx HTTP(80) 들어오면 강제로 HTTPS(443) 전환하도록 설정하기

 

[설정방법]

/conf/nginx.conf 설정 수정

 

Server 블록을 80 443으로 분리

server {
    listen       80;
    server_name  example.com;
    root         html;
}
server {
    listen       443 ssl https;
    server_name  example.com
    root         html;
}
 

 

 

그중 HTTP 제공하는 서버 블록에 location 설정을 추가해주면 됩니다.

HTTP요청을 HTTPS 301 Redirect 응답을 보내줍니다.

server {
listen 80;
server_name example.com;
root html;


location / {
        return 301 https://example.com$request_uri;
    }
}
 

 

!! 간단!

반응형

댓글