Login

Language :
TitleApache mod_jk VirtualHost 설정
Apache mod_jk VirtualHost setting
Writer이지섭Write DateFeb 4 2018Modify DateAug 12 2024View Count12588

[ httpd.conf ]

Include the httpd-vhosts.conf file.

Create the mod_jk.conf setting file and add it again.

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

...( skipping )...

Include conf/mod_jk.conf

[ mod_jk.conf ]

Loads the compiled and installed mod_jk.so module.

There's a way like JkMount.

But use the JkMountFile option to set the URI pattern to work with Tomcat.

LoadModule jk_module modules/mod_jk.so

<IfModule jk_module>
    JkWorkersFile    conf/workers.properties
    JkLogFile        logs/mod_jk.log
    JkLogLevel       info
    JkMountFile      conf/uri.properties
</IfModule>

[ workers.properties ]

Set the worker's name, port, and type to work when connecting to the Tomcat in mod_jk module.

Ports for the ajp13 protocol can be set in the server.xml file of the Tomcat.

If there are multiple worker (tomcat) names, separate them into commas (,) and list them in worker.list.

worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1

[ uri.properties ]

Let Tomcat process all the files in the first setup (/*).

Use the ! (Exclude) pattern to specify the URI pattern to be processed by Apache other than Tomcat.

/*=worker1

/*.jsp=worker1

/*.do=worker1

/api/*=worker1
!/=worker1 !/*.htm=worker1 !/*.Htm=worker1 !/*.hTm=worker1 !/*.htM=worker1 !/*.HTM=worker1 !/*.hTM=worker1 !/*.HtM=worker1 !/*.HTm=worker1 !/*.html=worker1 !/*.htmL=worker1 !/*.htMl=worker1 !/*.htML=worker1 !/*.hTml=worker1 !/*.hTmL=worker1 !/*.hTMl=worker1 !/*.hTML=worker1 !/*.Html=worker1 !/*.HtmL=worker1 !/*.HtMl=worker1 !/*.HtML=worker1 !/*.HTml=worker1 !/*.HTmL=worker1 !/*.HTMl=worker1 !/*.HTML=worker1 !/*.ico=worker1 !/*.icO=worker1 !/*.iCo=worker1 !/*.iCO=worker1 !/*.Ico=worker1 !/*.IcO=worker1 !/*.ICo=worker1 !/*.ICO=worker1 !/*.jpg=worker1 !/*.Jpg=worker1 !/*.jPg=worker1 !/*.jpG=worker1 !/*.JPG=worker1 !/*.jPG=worker1 !/*.JpG=worker1 !/*.JPg=worker1 !/*.png=worker1 !/*.Png=worker1 !/*.pNg=worker1 !/*.pnG=worker1 !/*.PNG=worker1 !/*.pNG=worker1 !/*.PnG=worker1 !/*.PNg=worker1 !/*.gif=worker1 !/*.Gif=worker1 !/*.gIf=worker1 !/*.giF=worker1 !/*.GIF=worker1 !/*.gIF=worker1 !/*.GiF=worker1 !/*.GIf=worker1 !/*.js=worker1 !/*.Js=worker1 !/*.jS=worker1 !/*.JS=worker1 !/*.css=worker1 !/*.Css=worker1 !/*.cSs=worker1 !/*.csS=worker1 !/*.CSS=worker1 !/*.cSS=worker1 !/*.CsS=worker1 !/*.CSs=worker1 !/*.txt=worker1

!/*.json=worker1

[ httpd-vhosts.conf ]

Apply uri.properties setting applied in mod_jk.conf to each VirtualHost (JkMountFile),

Add the syntax JkMountFile conf/uri.properties to the last part of each VirtualHost setup.

Note that examples of SSL setup are in the conf/extra/httpd-ssl.conf file.

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any  block.
#
<VirtualHost *:80>
    ServerAdmin webmaster@some.net
    DocumentRoot "/usr/local/apache-tomcat-8.5.24/webapps/ROOT"
    ServerName some.net
    ServerAlias www.some.net

    ErrorLog "logs/some.net-error_log"
    CustomLog "logs/some.net-access_log" common

    JkMountFile  conf/uri.properties

</VirtualHost>


<VirtualHost *:443>
    ServerAdmin webmaster@some.net
    DocumentRoot "/usr/local/apache-tomcat-8.5.24/webapps/ROOT"
    ServerName some.net
    ServerAlias www.some.net

    ErrorLog "logs/some.net-ssl-error_log"
    CustomLog "logs/some.net-ssl-access_log" common

    SSLEngine on

    SSLCertificateFile /etc/pki/tls/private/some.net_20180107B19T.crt.pem
    SSLCertificateKeyFile /etc/pki/tls/private/some.net_20180107B19T.key.pem
    SSLCertificateChainFile /etc/pki/tls/certs/chain-bundle.pem
    SSLCACertificateFile /etc/pki/tls/certs/AddTrustExternalCARoot.crt

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory "/usr/local/apache2/cgi-bin">
        SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

    CustomLog "/usr/local/apache2/logs/ssl_request_log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

    JkMountFile  conf/uri.properties

</VirtualHost>

 

When linking Apache and Tomcat by mod_jk module, in mod_jk.conf,

the JkMountFile setting is used to specify the URI pattern to be responsible for each server.

 

The point is that the VirtualHost setup also needs to specify the URI pattern

that each server is responsible for.

 

That way, the Jsp file will be processed by Tomcat.


Multiple Tomcat links on one Apache web server

Set the port and IP of Tomcat, and create each uri.properties file.

You can assign each mapping file to the JkMountFile from VirtualHost by host.

 

Because a worker is specified in the uri.properties file.

Several Tomcat can be linked.

 

(Environment)

 Apache : httpd-2.4.29

 mod_jk : tomcat-connectors-1.2.42

 Tomcat : apache-tomcat-8.5.24

 

[Web page referenced]

  http://tomcat.apache.org/connectors-doc/reference/uriworkermap.html

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

  http://truepia.tistory.com/276

  http://algina.tistory.com/158

  The Apache Tomcat Connectors - Reference Guide (1.2.49) - uriworkermap.properties configuration

Comment

Name               Password 
Content
덕분에 좋은 내용 잘 보고 갑니다.
정말 감사합니다.
Writer - 행인
Jul 18 2023
Check Password.

Please enter your password when registering your comment.