[httpd] https://{IP} 로 URL을 입력받았을 때, https://{domain name}으로 리다이렉션 시키는 방법

2024. 4. 11. 16:45·Middleware/웹서버

사내에 여러 보안 사항을 DEV 및 QA 서버에서 테스트 하기 위해,

기존 SSL이 적용되지 않은 DEV 및 QA 서버에 SSL을 적용하였는데,

https://{IP} 로 입력하여 해당 서비스에 접근할 경우, 다음과 같이 SSL이 적용되지 않는 문제를 발견하였다.

 

http://{IP} -> https://{domain name} 으로 리다이렉션하는 설정은 쉽게 넣었는데,

https://{IP} -> https://{domain name} 은 찾는게 쉽지 않았다...

 

참고로, http://{IP} -> https://{domain name} 이 방법은, 다음과 같은 방법으로 진행하였다.

<VirtualHost *:80>
    RewriteEngine on
    # IP가 123.123.123.123 이라고 가정
    RewriteCond %{HTTP_HOST} ^123\.123\.123\.123$
    RewriteRule (.*) https://service.mydomain.co.kr%{REQUEST_URI}
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "${Document_Root_Path}"
    ServerName service.mydomain.co.kr
    ErrorLog "|${HTTPD_HOME}/bin/rotatelogs ${HTTPD_HOME}/logs/site-error_log.%Y%m%d 86400 +540"
    CustomLog "|${HTTPD_HOME}/bin/rotatelogs ${HTTPD_HOME}/logs/site-access_log.%Y%m%d 86400 +540" combined

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://service.mydomain.co.kr%{REQUEST_URI} [L,R=301]

</VirtualHost>

 

물론 사이트를 단순히 접속하는 목적이라면, [고급] 탭을 눌러 안전하지 않은 연결을 통해 접속이 가능하지만,

사이트 관리자의 입장에서는 이런식으로 SSL을 우회할 가능성이 있기 때문에, https://{IP} 로 보내는 요청도 모두 DNS 서버에 등록된 domain name으로, 즉, https://{domain name} 으로 리다이렉션 시키고 싶어졌다.

 

나와 같은 고민을 한 해외 서버 관리자들이 꽤 있는 것 같은데, 아래 방법이 나의 케이스와 가장 잘 맞아 참고하였다.

https://serverfault.com/questions/993925/redirect-ip-address-to-domain-name-on-apache

 

Redirect IP address to domain name on apache

I am pretty computer savvy, but not with setting up web servers. I have a domain name that has an SSL certificate, so that https://example.org works and http://example.org redirects there. BUT, h...

serverfault.com


필자의 경우, https://{IP}의 리다이렉션 설정 전, 443 포트에 대한 VirtualHost 설정은 다음과 같았다.

<VirtualHost *:443>
    DocumentRoot ${SITE_DOCUMENT_ROOT_PATH}
    ServerName service.mydomain.co.kr
    
    SSLEngine On
    
    SSLProtocol -all +TLSv1.2 +TLSv1.3
    SSLCipherSuite HIGH:MEDIUM:!SSLv2:!PSK:!SRP:!ADH:!AECDH:!3DES:!RC4

    SSLCertificateFile ${Certificate_Path}
    SSLCertificateKeyFile ${Certificate_Keyfile_Path}

    ErrorLog "|${HTTPD_HOME}/bin/rotatelogs ${HTTPD_HOME}/logs/site-error_log.%Y%m%d 86400 +540"
    CustomLog "|${HTTPD_HOME}/bin/rotatelogs ${HTTPD_HOME}/logs/site-access_log.%Y%m%d 86400 +540" combined

    
    # WebLogic과 연동하기 위한 설정
    <IfModule mod_weblogic.c>
     WebLogicCluster {Server IP}:{Service Port}
     ConnectRetrySecs 2
     ConnectTimeoutSecs 10
     FileCaching OFF
     WLIOTimeoutSecs 18000
     DynamicServerList OFF
     Idempotent OFF
     MatchExpression *
    </IfModule>
    
</VirtualHost>

위 VirtualHost 설정을 아래와 같이, Rewrite 설정을 추가하였다.

 

여기서 주의할 점은, SSL 설정 이전에 Rewrite 관련 설정을 넣고, Rewrite의 조건을 원하는 domain name이 아닌 모든 요청일 경우, 원하는 domain name으로 무조건 리다이렉션 하도록 설정하는 것이다.

이러면, 원하는 domain name으로 들어온 요청은 조건에 해당하지 않으므로, 자연스레 SSL 설정으로 넘어가게 된다.

<VirtualHost *:443>
    DocumentRoot ${SITE_DOCUMENT_ROOT_PATH}
    ServerName service.mydomain.co.kr
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^service\.mydomain\.co\.kr$
    RewriteRule ^(.*)$ https://service.mydomain.co.kr$1 [R=permanent,L]
    
    SSLEngine On
    
    SSLProtocol -all +TLSv1.2 +TLSv1.3
    SSLCipherSuite HIGH:MEDIUM:!SSLv2:!PSK:!SRP:!ADH:!AECDH:!3DES:!RC4

    SSLCertificateFile ${Certificate_Path}
    SSLCertificateKeyFile ${Certificate_Keyfile_Path}

    ErrorLog "|${HTTPD_HOME}/bin/rotatelogs ${HTTPD_HOME}/logs/site-error_log.%Y%m%d 86400 +540"
    CustomLog "|${HTTPD_HOME}/bin/rotatelogs ${HTTPD_HOME}/logs/site-access_log.%Y%m%d 86400 +540" combined

    
    # WebLogic과 연동하기 위한 설정
    <IfModule mod_weblogic.c>
     WebLogicCluster {Server IP}:{Service Port}
     ConnectRetrySecs 2
     ConnectTimeoutSecs 10
     FileCaching OFF
     WLIOTimeoutSecs 18000
     DynamicServerList OFF
     Idempotent OFF
     MatchExpression *
    </IfModule>
    
</VirtualHost>

 

이게 정석적인 방법인지는 모르겠으나, 부디 나와 같은 삽질을 다른 사람들은 많이 하지 않도록,

https://{IP} -> https://{domain name} 방법을 이렇게 포스팅으로 공유해본다..!

저작자표시 비영리 변경금지 (새창열림)

'Middleware > 웹서버' 카테고리의 다른 글

[httpd] RedHat JBCS httpd 에서 Apache httpd로 이전하기 (1)  (0) 2024.04.07
[httpd] Apache httpd의 로그 삭제 스크립트 및 crontab 등록하여 로그 파일 삭제 자동화하기  (0) 2023.11.22
[Nginx] http → https 리다이렉션 및 SSL 인증서 적용 (Nginx ver.1.20.1 기준)  (1) 2023.11.03
[IIS] IIS(웹서버) 구축_Windows Server 2019 환경  (0) 2022.07.22
[httpd] Apache httpd Rewrite 모듈 설정 - 페이지 리다이렉션 하기  (0) 2022.06.10
'Middleware/웹서버' 카테고리의 다른 글
  • [httpd] RedHat JBCS httpd 에서 Apache httpd로 이전하기 (1)
  • [httpd] Apache httpd의 로그 삭제 스크립트 및 crontab 등록하여 로그 파일 삭제 자동화하기
  • [Nginx] http → https 리다이렉션 및 SSL 인증서 적용 (Nginx ver.1.20.1 기준)
  • [IIS] IIS(웹서버) 구축_Windows Server 2019 환경
코_노
코_노
일상의 불편함을 기술로서 해결하기 위해 노력하는 IT 엔지니어입니다. Contact point) jjh3706@gmail.com
  • 코_노
    코딩하는 주노 이야기
    코_노
  • 전체
    오늘
    어제
    • 코딩 이야기 (121)
      • DB (35)
        • SQL Server (MSSQL) (27)
        • MongoDB (2)
        • Hadoop Ecosystem (0)
        • SQLP 공부 (2)
      • 데이터 엔지니어링 (0)
        • Spark (0)
      • Middleware (21)
        • 웹서버 (7)
        • WAS (6)
        • WSGI (3)
        • 기타 (5)
      • OS (10)
        • Linux (7)
        • Windows (3)
      • Network (8)
      • Cloud (1)
        • AWS (1)
      • DevOps (8)
        • Container & K8S (0)
        • Github (3)
        • Ansible (2)
        • Terraform (3)
      • Security (3)
      • Observability (5)
      • CS 지식 | 기초 용어,개념 (7)
      • Python (1)
        • Flask (0)
      • Java (7)
        • JPA (0)
      • 안드로이드 (1)
      • 알고리즘 공부 (14)
  • 블로그 메뉴

    • 홈
    • 코딩 이야기
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    jvm 실행 옵션
    MongoDB Sharding
    SQL Server 2019 Restore
    MSSQL
    백준 python
    Windows AD
    SAS Intelligence Platform
    DBA
    SAS
    백준
    SQL Server 2019
    백준 골드 2
    SSMS
    백준 파이썬
    SQL Server
    db
    SAS 아키텍처
    백준 골드2
    백준 알고리즘
    백준 골드4
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
코_노
[httpd] https://{IP} 로 URL을 입력받았을 때, https://{domain name}으로 리다이렉션 시키는 방법
상단으로

티스토리툴바