0

I'm trying to setup my apache server to access certain folders when I type addresses like test1.example.com test2.example.com etc.

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. I've added example.com in hosts resolving to 127.0.0.1. So far no problems. I've enable vhost_alias and mod_rewrite in apache and I'm using this for my virtual server

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. Just to clear things up apache have permissions to read this directory so it's not this. 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. As you can see obviously it's not resolving the adress no matter that I've setup everything correcly.

Any help guys?

1 Answer 1

0

You need to add test.example.com and any other hostnames you want to use in the host file. The host file does not supports wildcard.

5
  • I'm trying to do dynamic virtual hosts, because I work with many project and every time I have to edit hosts file to add new domains... Can you sugest me any solution? I'm thinking of dnsmasq
    – Sh1d0w
    Apr 27, 2013 at 6:38
  • @Jensd My virtual hosts file is correct the problem is resolving donain to 127.0.0.1 ...
    – Sh1d0w
    Apr 27, 2013 at 7:08
  • You need to add all ips/hostnames to your dns/hosts-file
    – Jensd
    Apr 27, 2013 at 7:15
  • @shaddy, maybe you should revise your question to clarify your intention of that setup. Apr 27, 2013 at 8:35
  • In that case, if you own a domain name which is not used to host any website, you may add a wildcard A record, pointing to 127.0.0.1. However, putting such record on a domain name which you use for website will open those websites for XSS. Apr 27, 2013 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.