하은양 믿음군 효실맘 호홍홍집s

아파치 + 톰캣 연동시 하위디렉토리 도메인처리 본문

가벼운 배움/서버관련

아파치 + 톰캣 연동시 하위디렉토리 도메인처리

호홍홍집 2016. 9. 9. 16:34

1. mod_jk 이용

ex) www.good.co.kr/Rsv

아파치 셋팅(vhost 파일)
<VirtualHost *:80>
    SetEnvIf Request_URI .jpg image-request
    SetEnvIf Request_URI .gif image-request
    SetEnvIf Request_URI .jpeg image-request
    SetEnvIf Request_URI .swf image-request
    SetEnvIf Request_URI .png image-request
    SetEnvIf Request_URI .js image-request
    SetEnvIf Request_URI .css image-request
    SetEnvIf Request_URI .java image-request

    DocumentRoot /home/good
    Alias /Rsv /home/goodRsv
    ServerName www.good.co.kr
    JkMount /*.jsp ajp13
    JkMount /webapps/* ajp13
    JkMount /home/good/* ajp13
    JkMount /home/goodRsv/* ajp13
    ErrorLog logs/good-error_log
    CustomLog logs/good-access_log combined env=!image-request
</VirtualHost>

톰캣연동된 부분 셋팅(server.xml)
<Host name="www.good.co.kr" appBase="/home" unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
 <Context path="" docBase="good" debug="1" reloadable="true" crossContext="true" />
        <Context path="/Rsv" docBase="goodRsv" debug="1" reloadable="true" crossContext="true" />
</Host>

2. mod_proxy 이용

<VirtualHost *:80>
        ServerName www.abc.kr
        DocumentRoot /home/abc

        ProxyRequests Off
        ProxyPreserveHost On

        <Proxy *>
            Order deny,allow
            Allow from all
        </Proxy>

        ProxyPass /memorial http://192.168.1.40:18080/memorial
        ProxyPassReverse /memorial http://192.168.1.40:18080/memorial
        <Location /memorial>
            Order allow,deny
            Allow from all
        </Location>
</VirtualHost>

* 톰캣은 아래의 내부서버 IP에 해당 port로 설치되어 있음.
192.168.1.40:18080/memorial

참고 : https://www.lesstif.com/pages/viewpage.action?pageId=12943367

<VirtualHost _default_:443>

ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/home/all"
ServerName all.XXX.DDD.com:443
#ServerAlias www.dummy-host.example.com

ErrorLog "/usr/local/apache/logs/error_log"
TransferLog "/usr/local/apache/logs/access_log"


    # Put this in the main section of your configuration
    #     (or desired virtual host, if using Apache virtual hosts)
    ProxyRequests Off
    ProxyPreserveHost On

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ## localtax
    ProxyPass /localtax https://localhost/localtax
    ProxyPassReverse /localtax https://localhost/localtax
    <Location /localtax>
        Order allow,deny
        Allow from all
    </Location>
 
#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on
SSLProxyEngine on

SSLCertificateFile /usr/local/apache/conf/SSLfile/allCert.pem
SSLCertificateKeyFile /usr/local/apache/conf/SSLfile/all_keystore.key
SSLCertificateChainFile /usr/local/apache/conf/SSLfile/allCaChain.pem
SSLCACertificateFile /usr/local/apache/conf/SSLfile/allCa.pem
CustomLog "/usr/local/apache/logs/ssl_request_log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

// 톰캣에 설정부분
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
   maxThreads="150" miniSpareThreads="25" maxSpareThreads="75" enableLookups="false"
   disableUploadTimeout="true" acceptCount="100" debug="0" scheme="https" secure="true" 
   keystorePass="비밀번호" keystoreFile="/usr/local/apache/conf/SSLfile/all_keystore" 
   clientAuth="false" sslProtocol="TLS"
   ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA"
/>

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

3. mod_proxy 설치 & 설정 
출처: http://blog.pointbre.com/2794
 
동일 도메인에 대해서만 ajax 호출이 되는 문제를 풀기 위한 해법 중의 하나인 mod_proxy 사용방법이다.
다양한 응용이 가능하지만 이것만 해도 행복한 기능이다. ^^
 
1.버전에 맞는 아파치 소스 다운로드
wget http://apache.mirror.cdnetworks.com/httpd/httpd-2.2.31.tar.gz
 
2.압축 해제 후 module/proxy 디렉토리로 이동
tar xvzf httpd-2.2.31.tar.gz
/usr/local/src/httpd-2.2.31/modules/proxy
 
3.컴파일
/usr/local/apache2/bin/apxs -i -a -c mod_proxy.c proxy_util.c
/usr/local/apache2/bin/apxs -i -a -c mod_proxy_http.c proxy_util.c
/usr/local/apache2/bin/apxs -i -a -c mod_proxy_connect.c proxy_util.c
/usr/local/apache2/bin/apxs -i -a -c mod_proxy_ftp.c proxy_util.c

/usr/local/apache2/bin/apxs -i -a -c -I /usr/include/libxml2/ mod_xml2enc.c
/usr/local/apache2/bin/apxs -i -a -c -I /usr/include/libxml2/ -I ./ mod_proxy_html.c

4.httpd.conf 확인 & 수정
(1) 다음처럼 LoadModule에 추가되어있음을 확인
LoadModule proxy_module       modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module  modules/mod_proxy_http.so
LoadModule proxy_ftp_module   modules/mod_proxy_ftp.so