apachemod_jk | virtualhost不侦听doimain名称以将请求转发给tomcats

hiz5n14c  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(329)

现在我在工作上还有一个问题。我已经调整了配置,现在,根据url,请求应该被转发到后端的3个Tomcat。
如果url是www.mysite.com,那么请求应该转发到tomcat 1,依此类推。
当然,它们是virtualhost中的虚拟网站,或者至少我的服务器应该这么认为。然而,它不是这样工作的。如果我访问mysite.com,正如预期的那样,实际上会调用mysite.com,而不是将请求转发给Tomcat1。
当我调用localhost时,会直接显示tomcat的起始页,这实际上应该是localhost:8181的起始页。可以通过/app1..3联系Tomcat。所以这不是问题所在。
问题是:为了实现我的目标,我到底需要改变什么,在哪里改变?
httpd.conf

Listen 80       
NameVirtualHost *:80

<VirtualHost *:80>
        ServerName www.mysite.com
        RewriteEngine on
        RewriteRule ^/(.*)$/app1/$1 [l,PT]
        JkMount /* tomcat1
</VirtualHost>

<VirtualHost *:80>
        ServerName www.test.de
        RewriteEngine on
        RewriteRule ^/(.*)$/app2/$1 [l,PT]
        JkMount /* tomcat2
</VirtualHost>

<VirtualHost *:80>
        ServerName www.example.de
        RewriteEngine on
        RewriteRule ^/(.*)$/app3/$1 [l,PT]
        JkMount /* tomcat3
</VirtualHost>

“httpd-s”的输出

AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf/httpd.conf:48
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:

* :80                   is a NameVirtualHost

         default server www.mysite.com (/etc/httpd/conf/httpd.conf:50)
         port 80 namevhost www.mysite.com (/etc/httpd/conf/httpd.conf:50)
         port 80 namevhost www.test.de (/etc/httpd/conf/httpd.conf:57)
         port 80 namevhost www.example.de (/etc/httpd/conf/httpd.conf:64)
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex lua-ivm-shm: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex default: dir="/etc/httpd/run/" mechanism=default 
Mutex cache-socache: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex watchdog-callback: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
PidFile: "/etc/httpd/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48
xpcnnkqh

xpcnnkqh1#

[你的 RewriteRule 图案和替换之间缺少空格。]
重写将被发送到tomcat的uri路径通常不是一个好主意:servlet应用程序通常使用

<scheme>://<serverName>:<serverPort>/<contextPath>/relative/path/to/resource

ajp协议为tomcat提供了正确的 <scheme> , <serverName><serverPort> ,即 <contextPath> apache http服务器接收到的消息永远不会转发给tomcat。
因此,例如:
客户请求 http://example.com/index.html ,
您的重写规则将其更改为 http://example.com/app1/index.html 并将其发送给tomcat,
tomcat生成一个html页面,其中图像位于 http://example.com/app1/image.png ,
客户请求 http://example.com/app1/image.png 您的重写规则将其更改为 http://example.com/app1/app1/image.png ,这是不存在的。
一个简单的解决方案是将应用程序部署在客户端看到它们的相同上下文路径下:将所有应用程序重命名为 ROOT 在网站的根目录下部署它们。

相关问题