본문 바로가기

리눅스

[Apache] 웹서버에서 http를 https(SSL)로 리다이렉트하는 방법

반응형

웹서버에서 http를 https(SSL)로 리다이렉트하는 방법

rewrite 모듈 활성화

LoadModule rewrite_module modules/mod_rewrite.so

###httpd.conf
$ vim httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so

모듈 확인

httpd -M

$ httpd -M | egrep -i rewrite
 rewrite_module (shared)

가상호스트 설정

httpd-vhosts.conf 편집

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

$ vim httpd-vhosts.conf
...
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/var/www/wwwroot"
    ServerName test.sangchul.kr
    ServerAlias t.sangchul.kr
    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    CustomLog "|/usr/sbin/cronolog /logs/access/test.sangchul.kr-access-%Y%m%d.log" scombined
    ErrorLog "|/usr/sbin/cronolog /logs/error/test.sangchul.kr-error-%Y%m%d.log"
<Directory "/var/www/wwwroot">
    Options FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
</VirtualHost>

아파치 configure 문법 검사 및 재기동

###run syntax check for config files
$ apachectl -t
Syntax OK

$ systemctl restart httpd
Enter TLS private key passphrase for test.sangchul.kr:443 (RSA) : **********

$ ps -ef | grep -v grep | egrep httpd 
root     2575008       1  0 12:09 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   2575038 2575008  0 12:09 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   2575039 2575008  0 12:09 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   2575040 2575008  0 12:09 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   2575041 2575008  0 12:09 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache   2575253 2575008  0 12:09 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND

 

 

728x90
반응형