본문 바로가기

Server/Linux

[Apache/Linux] http를 https(SSL)로 리다이렉트(redirect) 설정

* 환경 : Apache Server / Linux

  - 시스템 http로 접속시 https(SSL)로 강제 리다이렉트 설정 방법

 

1. httpd.conf 설정파일 수정

<VirtualHost *:80>
	ServerName 127.0.0.1
		.
		.
        
	<IfModule mod_rewrite.c>
		RewriteEngine On
		RewriteCond %{HTTPS} off
		RewriteRule (.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
	</IfModule>

		.
		.
	/* JKMount 설정 */
	/* JkUnMount 설정 */
</VirtualHost>

 1) RewriteCond %{HTTPS} off

     - RewriteCond %{HTTPS} != on 으로 입력해도됨

 

 2) RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

     - ^(.*)$ 또는 (.*)$ 입력(찾아보니 두개 차이는 크게 없다고 하네요)

     - %{HTTP_HOST}%{REQUEST_URI} 또는 %{HTTP_HOST}/$1 으로 입력(차이점은 잘모르겠네요..)

     - R은 redirect 시킨다는 의미 (R=301 영구적 이동 , R=302 일시적 이동)

 

 

2. 아파치 재시작

# cd /${Apache}/bin
# ./apachectl configtest
Syntax OK
# ./apachectl restart

 1) cd /${Apache}/bin

     - ${Apache} 부분은 아파치 설치 위치 기입


 2) ./apachectl configtest

     - 명령어 실행 후 Syntax OK 나타나면 아파치 재시작 진행

 

 

 

 

'Server > Linux' 카테고리의 다른 글

[Linux/vi명령어] 리눅스 touch 하위폴더 포함 적용  (0) 2020.07.30