Reputation: 35
I have Apache2 running on domain mysite.com. I have following Apache virtualhosts:
mysite.com, admin.mysite.com, order.mysite.com, blog.mysite.com
Virtualhost mysite.com:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com 12.123.123.123 mysitehost.ip-12-123-123.eu
ServerAdmin [email protected]
SuexecUserGroup mysiteuser mysiteuser
AddHandler fcgid-script .php
DocumentRoot /var/www/root/www.mysite.com
<Directory "/var/www/root/www.mysite.com">
Options Indexes MultiViews FollowSymLinks +ExecCGI
FCGIWrapper /var/www/root/fcgi/php-fcgi-starter .php
Order allow,deny
allow from all
</Directory>
LogLevel warn
ErrorLog /var/www/root/logs/error.log
CustomLog /var/www/root/logs/access.log combined
</VirtualHost>
Virtualhost admin.mysite.com (all others are similiar):
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName admin.mysite.com
SuexecUserGroup mysiteuser mysiteuser
AddHandler fcgid-script .php
DocumentRoot /var/www/root/admin.mysite.com
<Directory "/var/www/root/admin.mysite.com">
Options Indexes MultiViews FollowSymLinks +ExecCGI
FCGIWrapper /var/www/root/fcgi/php-fcgi-starter .php
Order allow,deny
allow from all
</Directory>
LogLevel warn
ErrorLog /var/www/root/logs/error.log
CustomLog /var/www/root/logs/access.log combined
</VirtualHost>
My problem is that every other subdomains (that doesn't exist) will show the "/var/www/root/admin.mysite.com" content... For example if I type blaablaa.mysite.com to my browser, my admin.mysite.com will open.
Please tell me how to prevent that and how to set virtualdomain for subdomains that doesn't exist.
Upvotes: 1
Views: 1408
Reputation: 165
Just in case anyone stumbles across this, and if OP never actually got an answer, even though this should be on serverfault, I'll write an answer. The way you do it is to have your very last virtual host in your apache configuration to be a wildcard. This is what I use in mine:
#Any subdomain that doesn't exist is caught by this
<VirtualHost *:80>
ServerName tomg.xyz # replace with your website name. You can multiple of these virtual hosts for all of your domains on that server
DocumentRoot /var/www/tomcatch # choose where the "404, this subdomain doesn't exist" files are
ServerAlias *.tomg.xyz # Keeping the "*", change this to your domain
Options FollowSymLinks
<Directory "/var/www/tomcatch">
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
Upvotes: 4
Reputation: 70510
Most simple is: set up a 3rd virtual host with ServerName *.mysite.com
, and configure it to redirect to where you'd like it. Or, alternatively, you could of course not set a *.mysite.com
DNS entry anywhere....
Upvotes: 0