通过centos 8上的mod_jk将apache httpd重定向到tomcat

Posted

技术标签:

【中文标题】通过centos 8上的mod_jk将apache httpd重定向到tomcat【英文标题】:Redirect apache httpd to tomcat by mod_jk on centos 8 【发布时间】:2021-04-12 16:12:31 【问题描述】:

我试图强制 apache httpd 将一些请求重定向到 tomcat。我正在使用 mod_jk。 我的 testapp 可以通过https://www.myDomain.pl:8443/testapp 访问,但是如果通过https://www.myDomain.pl/testapp 运行,apache httpd 返回 404。

我做错了什么?请帮忙

这是我的配置文件更改:

/usr/local/tomcat9/conf/server.xml

 <Connector protocol="AJP/1.3"
            address="127.0.0.1"
           port="8009"
           redirectPort="8443"
            secretRequired="false"/>

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
           maxThreads="150" SSLEnabled="true">
    <SSLHostConfig>
            <Certificate certificateKeyFile="conf/server.key"
                     certificateFile="conf/server.crt"
                     certificateChainFile="conf/server.ca"
                     type="RSA" />
             </SSLHostConfig>
</Connector>

/etc/httpd/conf/httpd.conf

LoadModule jk_module /usr/lib/apache/mod_jk.so

JkWorkersFile "/etc/httpd/conf/workers.properties"
JkLogFile     "/var/log/mod_jk.log"
JkLogLevel  info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat     "%w %V %T"
JkShmFile     /var/log/httpd/mod_jk.shm

/etc/httpd/conf/workers.properties(整个文件)

worker.list=a
worker.a.type=ajp13
worker.a.host=localhost
worker.a.port=8009
worker.a.socket_timeout=10

/etc/httpd/conf/extra/httpd-vhosts.conf(整个文件)

  <VirtualHost myIP:80>
    ServerAdmin webmaster@localhost
    UserDir disabled
    DocumentRoot /var/www/html
    ServerName www.myDomain.pl
    ScriptAlias /cgi-bin/ /var/www/cgi-bin/
    CustomLog /var/log/httpd/homedir.log homedir
    CustomLog /var/log/httpd/access_log combined
    ErrorLog /var/log/httpd/error_log
    <IfModule !mod_ruid2.c>
        SuexecUserGroup webapps webapps
    </IfModule>
</VirtualHost>

<VirtualHost myIP:443 >
    ServerAdmin webmaster@localhost
    UserDir disabled
    DocumentRoot /var/www/html
    ServerName www.myDomain.pl
    ScriptAlias /cgi-bin/ /var/www/cgi-bin/
    CustomLog /var/log/httpd/homedir.log homedir
    CustomLog /var/log/httpd/access_log combined
    ErrorLog /var/log/httpd/error_log
    SSLEngine on
    SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt
    SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key
    SSLCACertificateFile /etc/httpd/conf/ssl.crt/server.crt
JkMount /testapp a
    <IfModule !mod_ruid2.c>
        SuexecUserGroup webapps webapps
    </IfModule>
</VirtualHost>

【问题讨论】:

【参考方案1】:

我不确定你的问题是什么,但我会尝试改变

JkMount /testapp a

JkMount / a

此外,您是否考虑过使用 ProxyPass 和 ProxyPassReverse (https://tomcat.apache.org/connectors-doc-archive/jk2/proxy.html)?

【讨论】:

以上是关于通过centos 8上的mod_jk将apache httpd重定向到tomcat的主要内容,如果未能解决你的问题,请参考以下文章

为啥 Ubuntu 14.04 上的 mod_jk 无法连接到 tomcat

Apache+Tomcat+mod_jk配置教程

centos7(apache+tomcat动静分离)#yyds干货盘点#

Apache 停止响应 SSL + mod_jk

apache代理多个tomcat实例如何做负载均衡

Apache/mod_jk 模块在运行一段时间后无法连接 jboss