Apache, Nginx http -> https 로 redirect
Apache, Nginx http -> https 로 redirect
사이트를 운영하다보면 보안 정책으로 “http://도메인주소” 를 사용할 수 없는 상황이 나옵니다.
웹브라우저에서
“http://원도메인주소” (http://example.com)
“http://www.원도메인주소” (http://www.원도메인주소)
“원도메인주소” (example.com)
“www.원도메인주소” (www.example.com)
4가지를 쳤을때 자동적으로 “https://원도메인주소” (https://example.com) 또는 “https://www.원도메인주소” (https://example.com) 으로 자동적으로 리다이랙트 되는 방법을 설명하겠습니다.
리눅스 서버에서 웹 서비스는 대부분 Apache, Nginx 를 사용합니다.
(SSL 인증서를 발급받고 적용시켰다는 가정하에 진행합니다.)
1. Apache
=====================================================
source설치
=====================================================
=====================================================
yum설치
=====================================================
# vi /etc/httpd/conf.d/vhosts.conf
=====================================================
source설치
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
=====================================================
yum설치
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
=====================================================
Category: LINUX