Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.


  Search this Thread
Old 09-11-2016, 01:43 AM   #1
Registered: Nov 2009
Posts: 49

Rep: Reputation: 15
Testing virtual host creation


I have created 3 virtual hosts within my virtual machine.
The DocumentRoot for two of the virtual machines are located in
/var/www/vhosts. The name of these two virtual hosts (ServerName) are & The index.html contents for both these servers are "COFFEE!" and "COKE!" respectively.

The 3rd virtual host is located in a directory called /website. I created an index.html for this virtual host in /website with the content "OMG SO NON STANDARD".

The SELinux setting for the /website directory was originally :
# ls -Z / | grep website
drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 website
# ls -Z /website/
-rw-r--r--. root root unconfined_u:object_r:default_t:s0 index.html
Changed it to :
# chcon --reference=/var/www /website/
# ls -Z / | grep website
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 website
# chcon --reference=/var/www/vhosts/ /website/index.html
Even after doing these changes, I am not able to see any output when I do :
# curl
It produces error like 'host not found'.

I then add all three virtual hosts, and into /etc/hosts, the same line as localhost.
I then restart httpd, and when I do the 'curl' command :
# curl
It produces output "COFFEE!". I then move the & to a different directory and restart httpd, and then I get the output desired from curl :

# curl
Today, I remove the, and from /etc/hosts, and restart httpd, and I still get the output same as above :

# curl
My question is, what is the correct way to get virtual hosts to produce the output desired from index.html without getting any errors. Is it really required to add the VirtualHost "ServerName" (in this case,, in /etc/hosts?

If so then why does using curl on give the output COFFEE! which is the content of
Old 09-12-2016, 10:59 AM   #2
Senior Member
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,854

Rep: Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148Reputation: 1148
Originally Posted by anaigini45 View Post
Is it really required to add the VirtualHost "ServerName" (in this case,, in /etc/hosts?
It's not necessary but it's by far the easiest method for testing. There is a method using curl that allows you to pass the name of the required host as a parameter for example:
curl --header 'Host:' http://localhost
curl --resolve
So you can see it's easier for testing to just add the hosts to /etc/hosts and have names resolve "correctly"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Testing out distros in a virtual machine may give virtual results punchy71 Linux - Newbie 4 06-11-2014 06:12 PM
Ping to Honeyd virtual host replying Destination Host Unreachable Doejohn Linux - Networking 1 05-18-2014 04:43 AM
Virtual host inside Virtual Host, apache2 pinguim007 Linux - Server 1 08-22-2013 03:49 AM
[SOLVED] Bash script to Automate the Virtual Host creation process!! anishkumarv Linux - Newbie 3 03-14-2011 11:03 PM
virtual host for local testing tr3s Red Hat 1 09-02-2003 01:50 PM > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 12:34 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration