JkMount 基于 FQDN 实现多应用

JkMount 基于 FQDN 实现多应用

使用 Apache HTTPD 和 Tomcats,我必须在不同的 URL 上运行两个不同的应用程序。2 个 Tomcat 正在为其自己的应用程序提供服务。

  1. www.abc.com

  2. www.xyz.com

我的 Worker.properties 是

worker.list=tomcat1,status, tomcat2

# Define Tomcat1 for Application 1 accessed on www.abc.com
worker.tomcat1.port=8009 
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13 
worker.tomcat1.lbfactor=1

# Define Tomcat2 for Application 2 accessed on www.xyz.com
worker.tomcat2.port=8022
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
#

我的虚拟主机和 httpd.conf 中的相关内容是

<IfModule mod_jk.c>
    JkWorkersFile /etc/httpd/conf/workers.properties
    JkShmFile /var/log/httpd/mod_jk.shm
    JkLogFile /var/log/httpd/mod_jk.log
    JkLogLevel error
    JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
</IfModule>
<VirtualHost *:80>
    ServerName www.abc.com
    ErrorLog "/var/log/httpd/www.abc.com-error_log"
    CustomLog "/var/log/httpd/www.abc.com-access_log" common

    RewriteEngine On

      RewriteCond %{SERVER_PORT} !^443$
      RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L]

    JkMount /* tomcat1


</VirtualHost>

<VirtualHost *:443>

ServerName www.abc.com:443
ServerAlias abc
ErrorLog "/var/log/httpd/ssl-443-error_log"
CustomLog "/var/log/httpd/ssl-443-access_log" common
LogLevel error
    SSLEngine on
    SSLProtocol all -SSLv2

    SSLCertificateKeyFile /etc/httpd/conf/abc.key
    SSLCertificateFile /etc/httpd/conf/abc.crt
    SSLCertificateChainFile /etc/httpd/conf/abc-g2-g1.crt

    <Files ~ "\.(cgi|shtml|phtml|php3?)$">
        SSLOptions +StdEnvVars
    </Files>
    <Directory "/var/www/cgi-bin">
        SSLOptions +StdEnvVars
    </Directory>

SetEnvIf User-Agent ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

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

            RewriteCond %{SERVER_PORT} =443
            RewriteRule ^(.*)$ http://%{SERVER_NAME}:80$1 [R,L]

            JkMount /* tomcat1
</VirtualHost>                                  

############################################################################################
<VirtualHost *:80>
    ServerName www.xyz.com
    ErrorLog "/var/log/httpd/xyz.com-error_log"
    CustomLog "/var/log/httpd/xyz.com-access_log" common

         #  RewriteEngine On
         #  RewriteCond %{SERVER_PORT} !^9443$
         #  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L]

   JkMount /* tomcat2

</VirtualHost>

当然,我已经添加了
NameVirtualHost *:80 来与多个虚拟主机一起使用

它的作用是将所有请求发送到第一个主机 [abc.com],这两个 URL 分别是 www.abc.com www.xyz.com

对于 www.xyz.com 我需要它转到 tomcat2 而不是 tomcat1

答案1

我找到了问题,两个 URL 的 SSL 证书不同。Apache 路由到默认 VirtualHost 0:443 [第一个]。

我得到的解决方案是 NameBasedSSLVHostsWithSNI

您可能会发现此链接很有帮助

相关内容