How to configure Apache2 to accept automatic subdomains?

So I have written a configuration file and activated it / reloaded Apache2:

 <virtualhost *:80="">ServerAdmin my@email.com
  ServerName  *.mydomain.com

  DocumentRoot /home/xx/mydomain.com/.sub
  <directory>Options Indexes SymLinksIfOwnerMatch
    AllowOverride All
    Order allow,deny
    Allow from all</directory> 

  ErrorLog  /home/xx/logs/error.log
  CustomLog /home/xx/logs/access.log combined</virtualhost> 

When I visit whatever.mydomain.com, it still gives me this error:

Forbidden

You don't have permission to access / on this server.

What am I doing wrong? Thanks!

2 Replies

As far as I can gather, if you're going to use wildcard hostnames (*.example.com), you must specify one of them in ServerName, and then use the wildcard in ServerAlias.

It doesn't seem like ServerName supports the use of wildcards. ServerAlias does, though.

Second, make sure your home directory (as well as subdirectories and files in the tree in it) is readable by the user and group Apache runs as (it's usually www-data or apache for both the user and the group).

@NeonNero:

As far as I can gather, if you're going to use wildcard hostnames (*.example.com), you must specify one of them in ServerName, and then use the wildcard in ServerAlias.

It doesn't seem like ServerName supports the use of wildcards. ServerAlias does, though.

Second, make sure your home directory (as well as subdirectories and files in the tree in it) is readable by the user and group Apache runs as (it's usually www-data or apache for both the user and the group).

Thanks a lot, Neon. That does the trick. :)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct