[Centos7] Apache HTTP -> HTTPS로 리다이렉트

2022.07.19 - [OS & Server/Linux] - [Centos7] Apache SSL 설정
[Centos7] Apache SSL 설정
[Centos7] Apache SSL 설정 OpenSSL 설치 # openSSL 설치 확인 $ find / -name openssl # openSSL 설치 $ yum install openssl mod_SSL 설치 $ yum -y install mod_ssl 개인키 생성 > CSR 생성 > 자체적..
jiurinie.tistory.com
지난 시간에 위와 같이 Apache에 SSL 설정을 하여 HTTPS 프로토콜로 웹 서비스를 제공할 수 있도록 하였다. 위 설정은 HTTPS통신은 제공하지만 HTTP 통신도 같이 제공하게 된다. 사용자가 HTTP로 접근 시 HTTPS 로 리다이렉션 해주는 설정을 해보자.
- vhost.conf
# Apache 홈의 conf.d 디렉토리로 이동 $ cd /etc/httpd/conf.d # virtual host 설정파일 생성 vi vhost.conf <VirtualHost *:80> DocumentRoot /var/www/html ServerName www.playground.co.kr RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </VirtualHost>
- 서비스 재시작
$ service httpd restart
참고 : https://httpd.apache.org/docs/current/mod/mod_rewrite.html
mod_rewrite - Apache HTTP Server Version 2.4
Apache Module mod_rewrite Summary The mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly. By default, mod_rewrite maps a URL to a filesystem path. However, it can also be u
httpd.apache.org
'OS & Server > Linux' 카테고리의 다른 글
OpenSSL을 이용한 .PFX 인증서를 .CRT & .KEY로 변환하기 (0) | 2022.08.03 |
---|---|
[Centos7] Apache 도메인 네임 리다이렉트 (0) | 2022.07.20 |
[Centos7] Apache SSL 인증서 비밀번호 검증 없애기 (0) | 2022.07.19 |
[Centos7] Apache SSL 설정 (0) | 2022.07.19 |
[Apache Tomcat] 톰캣 일자별 로그 나누기 (0) | 2022.07.19 |
댓글