日期:2014-05-16  浏览次数:20810 次

apache 一个目录配置多个域名都可以访问。
apache 2.2

在httpd-vhosts.conf里怎么配置一个域名都访问一个地方。

现在我的做法是配置三个VirtualHost,很正常,就是想把他们都整在一起。

试了一下:ServerName kj.scsyyjxh.org kj.scsyx.com kj.scsyx.org
这样做不行。

哪位知道怎么做。

<VirtualHost *:80>
ServerName kj.scsyyjxh.org
ProxyPass / http://localhost:89/
ProxyPassReverse / http://localhost:89/
</VirtualHost>


<VirtualHost *:80>
ServerName kj.scsyx.org
ProxyPass / http://localhost:89/
ProxyPassReverse / http://localhost:89/
</VirtualHost>

<VirtualHost *:80>
ServerName kj.scsyx.com
ProxyPass / http://localhost:89/
ProxyPassReverse / http://localhost:89/
</VirtualHost>
------解决方案--------------------
apache 中 ServerAlias让多个域名绑定到同一空间 

在apache的虚拟主机中,如果书写了。ServerAlias www.cq.com www.gd.com这样的语句,就可以给虚拟主机增加多个域名,而且这些域名都访问同一个站点。

#Listen 81
<VirtualHost *:80>
    ServerName www.bj.com:80
    ServerAdmin webmaster@localhost
    DocumentRoot "F:/webserver/htdocs/host"
    ServerAlias www.cq.com www.gd.com
    ErrorLog "logs/host-error.log"
    CustomLog "logs/host-access.log" common
    <Directory "F:/webserver/htdocs/host">
    Options Indexes FollowSymLinks Includes 
IndexOptions FancyIndexing ScanHTMLTitles 
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
ScriptAlias /cgi-bin/ "F:/webserver/htdocs/host/cgi-bin/"
<Directory "F:/webserver/htdocs/host/cgi-bin/">
    AllowOverride None
    Options Indexes FollowSymLinks ExecCGI
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

上面的代码会让三个域名都访问到同一个空间。
------解决方案--------------------
<VirtualHost *:80>
ServerName kj.scsyyjxh.org
ServerAlias kj.scsyx.com  kj.scsyx.org  
ProxyPass / http://localhost:89/
ProxyPassReverse / http://localhost:89/
</VirtualHost>

ServerAlias kj.scsyx.com  kj.scsyx.org      //加上这个
------解决方案--------------------
<VirtualHost *:80>
ServerName dj1k.cn
ServerAlias dj1k.cn *.dj1k.cn dj3q.com
DocumentRoot "F:/MyWeb/WebRoot/dj1k.cn"
</VirtualHost>