我在RHEL 5.3中使用httpd-2.2.3-22。
如何根据URLredirect到Linux中不同的文档根目录。
例:
testdomain.com的文档根目录是/var/www/vhost/testdomain.com/httpdocs
如果URL是http://web1.testdomain.com,那么它应该将文档根指向/var/www/vhost/testdomain.com/httpdocs/web1。
如果URL是http://web2.testdomain.com,那么它应该将文档根指向/var/www/vhost/testdomain.com/httpdocs/web2。
其中web1和web2是父文档根目录下的两个不同的文件夹。
请让我知道如何在这种情况下configurationApache?
温暖的问候
Supratik
您需要为您的服务器configuration虚拟主机。 在RHEL上的/ etc / httpd / conf中应该有configuration文件(如果你有自定义的版本,可能是/ etc / apache2)。 打开httpd.conf并编辑底部附近的虚拟主机部分。
例如,你可以插入文件(取自下面的链接)
Listen 80 NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /var/www/vhost/testdomain.com/httpdocs/web1 ServerName web1.testdomain.com </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/vhost/testdomain.com/httpdocs/web2 ServerName web2.testdomain.com </VirtualHost>
如果Apache正在侦听端口80(http,默认)。 那么你需要重新启动Apache(/etc/init.d/httpd restart或“apache2 restart”)
请看看Apache虚拟主机
Re:无法添加虚拟主机
如果无法添加虚拟主机,则不太可能进一步更改apache和系统configuration。 我看到的唯一解决scheme是
如果你不介意使用另一个端口(例如不是80),你可以安装nginx,这个configuration非常简单,它将接受一个自定义的configuration文件,并将其configuration为接受来自端口5000的连接(例如http: //web1.testdomain.com:5000 ),前提是
在另一个Web服务器上托pipe文档文件,并更新testdomain.com的DNS以使web1 / 2子域名parsing为新的Web服务器IP地址
这听起来像你正在寻找dynamic的虚拟主机。 在这个Apache文档中有一篇很好的文章:
dynamicconfiguration的大量虚拟主机
有多种方法可以做到这一点,但最灵活的可能是mod_rewrite。 根据您的示例,您可以使用以下虚拟主机configuration:
<VirtualHost *> ServerName testdomain.com ServerAlias *.testdomain.com RewriteEngine on RewriteMap lowercase int:tolower # check the hostname is right so that the RewriteRule works RewriteCond ${lowercase:%{SERVER_NAME}} ^[a-z0-9-]+\.testdomain\.com$ # concatenate the virtual host name onto the start of the URI # the [C] means do the next rewrite on the result of this one RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C] # now create the real file name RewriteRule ^([a-z0-9-]+)\.testdomain\.com/(.*) /var/www/vhost/testdomain.com/httpdocs/$1/$2 </VirtualHost>
创build两个虚拟主机 ,每个都有自己的DocumentRoot 。