繁体   English   中英

解决虚拟主机Apache 2

[英]Resolving virtual hosts apache 2

当我键入诸如test1.example.com test2.example.com等地址时,我尝试将我的apache服务器设置为访问某些文件夹。

到目前为止,我阅读并做了很多事情,但都没有成功。 如果您能帮助我,我将非常感谢。

因此,首先,我将ubuntu 12.10用作桌面,并在那里建立了apache服务器。 我在解析为127.0.0.1的主机中添加了example.com。 到目前为止没有问题。 我已在apache中启用vhost_alias和mod_rewrite,并将其用于我的虚拟服务器

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

   RewriteEngine On

   RewriteCond %{HTTP_HOST} !^(www\.)?([^\.]+).example.com$
   RewriteRule ^(.*) $1 [F]

   VirtualDocumentRoot /home/example/server/projects/%1/public_html

     <Directory />
                Options FollowSymLinks
                AllowOverride all
        </Directory>
        <Directory /home/radoslav/server/projects>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>

   #log file for this server
   CustomLog /var/log/apache2/example.com.log combined
</VirtualHost>

但是,当我打开test.example.com时,它说浏览器可以找到test.example.com,无论我在指定的路径中是否有此目录。 只是为了清除问题,apache有权读取该目录,所以不是这个目录。 当我从控制台ping example.com时,我会ping通,但如果ping test.example.com时,我会收到找不到主机的错误。 如您所见,无论我是否正确设置所有内容,都无法解决地址问题。

有帮助吗?

您需要在主机文件中添加test.example.com和要使用的任何其他主机名。 主机文件不支持通配符。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM