简体   繁体   English

解决虚拟主机Apache 2

[英]Resolving virtual hosts apache 2

I'm trying to setup my apache server to access certain folders when I type addresses like test1.example.com test2.example.com etc. 当我键入诸如test1.example.com test2.example.com等地址时,我尝试将我的apache服务器设置为访问某些文件夹。

So far I read and did many things but with no success yet. 到目前为止,我阅读并做了很多事情,但都没有成功。 I'll be very thankful if you can help me. 如果您能帮助我,我将非常感谢。

So to start I'm using ubuntu 12.10 as my desktop and I've set up apache server there. 因此,首先,我将ubuntu 12.10用作桌面,并在那里建立了apache服务器。 I've added example.com in hosts resolving to 127.0.0.1. 我在解析为127.0.0.1的主机中添加了example.com。 So far no problems. 到目前为止没有问题。 I've enable vhost_alias and mod_rewrite in apache and I'm using this for my virtual server 我已在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>

But when I open test.example.com it says that browser can find test.example.com, no matter that I have this directory in the path specified. 但是,当我打开test.example.com时,它说浏览器可以找到test.example.com,无论我在指定的路径中是否有此目录。 Just to clear things up apache have permissions to read this directory so it's not this. 只是为了清除问题,apache有权读取该目录,所以不是这个目录。 When I ping example.com from console I get ping but if I ping test.example.com I get error that can not find host. 当我从控制台ping example.com时,我会ping通,但如果ping test.example.com时,我会收到找不到主机的错误。 As you can see obviously it's not resolving the adress no matter that I've setup everything correcly. 如您所见,无论我是否正确设置所有内容,都无法解决地址问题。

Any help guys? 有帮助吗?

You need to add test.example.com and any other hostnames you want to use in the host file. 您需要在主机文件中添加test.example.com和要使用的任何其他主机名。 The host file does not supports wildcard. 主机文件不支持通配符。

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

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