apache虚拟主机和;“动态”;领域

apache虚拟主机和;“动态”;领域,apache,dynamic,alias,virtualhost,restart,Apache,Dynamic,Alias,Virtualhost,Restart,我有一个响应多个域的java应用程序,每个域使用一个特定的apache虚拟主机。这是因为Apache在服务静态资源方面比tomcat快 需要在运行时执行此操作,而无需重新启动apache配置。 要执行此操作,我将使用VirtualDocumentRoot指令,如下所述: AddType text/html .html .shtml AddOutputFilter INCLUDES .html .shtml NameVirtualHost *:80 UseCanonicalName Off &l

我有一个响应多个域的java应用程序,每个域使用一个特定的apache虚拟主机。这是因为Apache在服务静态资源方面比tomcat快

需要在运行时执行此操作,而无需重新启动apache配置。 要执行此操作,我将使用VirtualDocumentRoot指令,如下所述:

AddType text/html .html .shtml
AddOutputFilter INCLUDES .html .shtml

NameVirtualHost *:80
UseCanonicalName Off
<VirtualHost *:80>
    ServerName domain.com
    ServerAlias *

    # Define virtual host directory, using entire domain
    VirtualDocumentRoot /path/to/whosts/%0

    # Define directory access
    <Directory "/path/to/whosts/">
        Options -Indexes MultiViews +Includes
        Order allow,deny
        Allow from all
    </Directory>

    # Define Java Proxies
    <Proxy *>
        AddDefaultCharset Off
        Order deny,allow
        Allow from all
    </Proxy>

    # Allow Libs (static resources) to access apache directly
    ProxyPass /libs !
    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>
AddType text/html.html.shtml
AddOutputFilter包含.html.shtml
名称虚拟主机*:80
UseCononicalName关闭
ServerName域名.com
服务器别名*
#使用整个域定义虚拟主机目录
VirtualDocumentRoot/path/to/whosts/%0
#定义目录访问
选项-索引多视图+包含
命令允许,拒绝
通融
#定义Java代理
添加默认字符集
命令拒绝,允许
通融
#允许Libs(静态资源)直接访问apache
ProxyPass/libs!
ProxyPass/ajp://localhost:8009/
ProxyPassReverse/ajp://localhost:8009/
这不起作用,因为如果我尝试访问www.domain.com,与访问domain.com不同

你认为注册一个从www.domain.com到domain.com的符号链接是个好主意吗

还有别的办法吗?我在apache管理方面真的很差

非常感谢


Ciao,Davide.

一个好方法是决定哪种类型的URL应该是规范的URL,并使用
mod_rewrite
将URL重定向到它-例如,将请求匹配到
domain.com
并将它们重定向到
www.domain.com
。在网上有很多关于如何做到这一点的教程,你应该可以很容易地找到

在我的脑海里,你可以使用类似的东西:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.$ [NC]
RewriteRule ^(.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
但是,如果您使用SSL,由于硬编码的
http://
,这将导致问题。我认为您可以将重写规则行更改为以下内容以避免:

RewriteRule ^(.*) %{SERVER_PROTOCOL}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

我经常使用符号链接将多个域链接到同一个webroot,在进行类似的配置时,该解决方案没有明显的危害,因此绝对没有理由回避它