Question

Issue with virtual hosts on centos

Posted August 14, 2013 6.5k views
I successfully setup virtual hosts on my droplet with CentOS 6.4 x32 I was following this tutorial. https://www.digitalocean.com/community/articles/how-to-set-up-apache-virtual-hosts-on-centos-6 Everything is good except, some issues. 1. If I setup virtual hosts, my default landing page is changed and pointing to one of my domain location. I want it to be some specific page or default CentOS setup page. This http://i.imgur.com/NLSJR.png After setting up virtual hosts, my default page is one of my domains page which I do not want. 2. www.domain.com and domain.com are working fine and pointing to same location/page. But if I type a.domain.com or random.domain.com, it still points to my that location which I do not want. I want it to give error. I assume this random subdomains are pointing to main domain because I added wildcard entry *.domain.com as ServerAlias in httpd.conf. But if I do not add this wildcard then random subdomains points to one of my different domain. Any ideas on these issues.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
4 answers
How many virtual hosts did you create? Do they all have different DocumentRoots? Where exactly did you declare the wildcard entry? In a specific vhost?
I have created 4 virtual hosts right now. And they do have all different DocumentRoot. Here is virtual host entry.


ServerAdmin webmaster@mydomain.com
DocumentRoot /home/myuser/mydomain.com/public
ServerName www.mydomain.com
ServerAlias mydomain.com
DirectoryIndex index.html index.php
ErrorLog /home/myuser/mydomain.com/log/error.log
CustomLog /home/myuser/mydomain.com/log/access.log combined

<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
DocumentRoot /home/myuser/mydomain.com/public
ServerName www.mydomain.com
ServerAlias mydomain.com
DirectoryIndex index.html index.php
ErrorLog /home/myuser/mydomain.com/log/error.log
CustomLog /home/myuser/mydomain.com/log/access.log combined
</VirtualHost>
You have to set up a default catch-all virtualhost:

http://httpd.apache.org/docs/2.0/vhosts/examples.html#default
Submit an Answer