블로그 이미지
좋은느낌/원철
이것저것 필요한 것을 모아보렵니다.. 방문해 주셔서 감사합니다..

calendar

1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

Notice

    2009. 6. 30. 10:20 개발/JSP/Servlet

    Apache 와 Tomcat 을 연동시 아파치에서는 정적인파일 (이미지, js, html 등등) 을 처리하게 하고 톰캣에서는 동적인 파일들을 처리하도록 하는것이 가장 중요한 포인트입니다.

    대용량 트래픽을 유발하는 서비스의 경우는 이미지 파일 이나, js 파일 등을 아래와 같이 서브 도메인으로 만들어서 물리적으로 다른서버에 두게 하는경우가 일반적인 적용 가능한 경우입니다.

    예) 이미지, js 파일 등등 -> img.onjava.co.kr  (일반적으로 이미지 서버 또는 파일서버)
         동적인 파일             -> www.onjava.co.kr (웹서버)
         www.onjava.co.kr 내의 html 에서 img 를 호출시 <img src="http://img.onjava.co.kr/xxx/xx.jpg"> 와 같은 형태로
         처리.


    하지만, 비용적인 측면이나 많은 트래픽이 생기지 않는 웹서버의 경우에는 하나의 물리적인 서버에서 아파치와 톰캣의 역할을 적절하게 나눠서 운영한다면 효과적인 서버운영을 할수가 있습니다.


    1. 아파치 WebRoot가 /usr/local/apache/htdocs 이고,
        톰캣 WebRoot 가 /home/web/source/onjava/WebRoot 인 
    경우
        
        - 톰캣에서는 파일 확장자가 jsp인 파일만 처리하도록 

        - 아파치에서는 jsp 파일 외의 파일들 (이미지 파일, html 파일 등등) 을 처리하도록 하기 위해서 아래와 같이 설정해준다.
       
        httpd.conf 파일내에서 
      ---------------------------------------------------------------------------------------------------------------------------------------------------------------     
      DocumentRoot "/usr/local/apache/htdocs"
        
      <Directory "/usr/local/apache/htdocs">
        #
        # Possible values for the Options directive are "None", "All",
        # or any combination of:
        #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
        #
        # Note that "MultiViews" must be named *explicitly* --- "Options All"
        # doesn't give it to you.
        #
        # The Options directive is both complicated and important.  Please see
        # http://httpd.apache.org/docs/2.2/mod/core.html#options
        # for more information.
        #
         Options FollowSymLinks

        #
        # AllowOverride controls what directives may be placed in .htaccess files.
        # It can be "All", "None", or any combination of the keywords:
        #   Options FileInfo AuthConfig Limit
        #
         AllowOverride None

        #
        # Controls who can get stuff from this server.
        #
         Order allow,deny
         Allow from all

    </Directory>

    # 아래와 같이 WebRoot 경로를 하나더 추가해 준다.

    <Directory "/home/web/source/onjava/WebRoot">
        #
        # Possible values for the Options directive are "None", "All",
        # or any combination of:
        #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
        #
        # Note that "MultiViews" must be named *explicitly* --- "Options All"
        # doesn't give it to you.
        #
        # The Options directive is both complicated and important.  Please see
        #
    http://httpd.apache.org/docs/2.2/mod/core.html#options
        # for more information.
        #
         Options FollowSymLinks

        #
        # AllowOverride controls what directives may be placed in .htaccess files.
        # It can be "All", "None", or any combination of the keywords:
        #   Options FileInfo AuthConfig Limit
        #
         AllowOverride None

        #
        # Controls who can get stuff from this server.
        #
         Order allow,deny
         Allow from all

    </Directory>

    # 톰캣과 연동을 위한 추가 소스 부분 (httpd.conf 파일의 맨 마지막 부분에 추가)

    <IfModule mod_jk.c>
      JkWorkersFile "/usr/local/apache/conf/workers.properties"
    </IfModule>

    # mod_jk.so 파일은 아파치사이트에서 다운받으면 된다.
    LoadModule jk_module "/usr/local/apache/modules/mod_jk.so" 

    #Configure mod_jk

    JkWorkersFile conf/workers.properties
    JkLogFile logs/mod_jk.log
    JkLogLevel info

    JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

    JkRequestLogFormat "%w %V %T"

    #Root context

    JkMount /*.jsp ajp13           -> 톰캣에서는 jsp 만 처리한다. (JkMount 에 추가된 파일만이 톰캣에서 처리하게 된다)
    #JkMount /*.html ajp13           -> 주석처리된 부분들은 모두 아파치에서 처리하게 된다.
    #JkMount /*.js ajp13
    #JkMount /*.jpg ajp13
    #JkMount /*.gif ajp13
    #JkMount /*.jpeg ajp13

    AddDefaultCharset UTF-8

    ----------------------------------------------------------------------------------------------------------------
    workers.properties 파일
        workers.tomcat_home=/usr/local/tomcat
        workers.java_home=/usr/local/java
        ps=\
        worker.list=ajp13
        worker.ajp13.port=8009
        worker.ajp13.host=localhost
     


    2. 위의 설정후에 jsp 파일이외의 이미지, html, js 파일 등은 /usr/local/apache/htdocs 에 위치시켜야 제대로 서비스가 가능하다. 당연히 톰캣에서 처리해야할 jsp 파일들은
    /home/web/source/onjava/WebRoot 에 위치시키면 된다.

    posted by 좋은느낌/원철