我在让附加虚拟主机正确代理 Apache/Tomcat 时遇到了问题。基本上,我有一个主虚拟站点,它代理到 Tomcat,并且工作正常。但是,我设置的附加虚拟主机不起作用。它们都返回到主站点。这是我第一次设置它,所以我显然做了一些 [可能很简单] 的事情导致了问题。
<VirtualHost *:80>
ServerAdmin webmaster@secondary_domain.com
ServerName secondary_domain.com
ServerAlias www.secondary_domain.com
ProxyPreserveHost On
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
DocumentRoot /var/www/secondary_domain.com
DirectoryIndex index.jsp
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/secondary_domain.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/www/secondary_domain.com/logs/error.log
LogLevel warn
CustomLog /var/www/secondary_domain.com/logs/access.log combined
<IfModule mpm_itk_module>
AssignUserId user userg
</IfModule>
这是 tomcat server.xml 文件
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
<!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
<!-- See proxy documentation for more information about using this. -->
<!--
<Connector port="8082"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" acceptCount="100" connectionTimeout="20000"
proxyPort="80" disableUploadTimeout="true" />
-->
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host). -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
-->
<!-- Define the top level container in our container hierarchy -->
<Engine name="Catalina" defaultHost="localhost">
<Host name="primary_domain.com" appBase="/var/www/primary_domain.com"/>
<Host name="secondary_domain.com" appBase="/var/www/secondary_domain.com">
<alias>www.secondary_domain.com</alias>
</Host>
答案1
仅根据一个虚拟主机的配置很难猜测,但可能有几个原因:
确保您的
<VirtualHost>
规格符合您的NameVirtualHost
指令。例如,您可能有
NameVirtualHost *:80
,因此您的新虚拟主机需要设置为<VirtualHost *:80>
,并使用适当的ServerName
/ServerAlias
配置来接收请求。为了确保 Tomcat 拥有需要发送给不同
appBase
主机名的信息,您需要确保ProxyPreserveHost
所有站点都已启用该功能。