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

Notices


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

Rep: Reputation: 15
Testing virtual host creation


Hi,

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 beta.example.com & example.com. 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 :
Code:
# 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 :
Code:
# 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/example.com/index.html /website/index.html
Even after doing these changes, I am not able to see any output when I do :
Code:
# curl non.example.com
It produces error like 'host not found'.

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

Code:
# curl non.example.com
OMG SO NON STANDARD
Today, I remove the beta.example.com, example.com and non.example.com from /etc/hosts, and restart httpd, and I still get the output same as above :

Code:
# curl non.example.com
OMG SO NON STANDARD
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 example.com, beta.example.com, non.example.com) in /etc/hosts?

If so then why does using curl on non.example.com give the output COFFEE! which is the content of beta.example.com?
 
Old 09-12-2016, 10:59 AM   #2
TenTenths
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
Quote:
Originally Posted by anaigini45 View Post
Is it really required to add the VirtualHost "ServerName" (in this case example.com, beta.example.com, non.example.com) 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:
Code:
curl --header 'Host: beta.example.com' http://localhost
or
Code:
curl --resolve beta.example.com:80:127.0.0.1 http://beta.example.com/
So you can see it's easier for testing to just add the hosts to /etc/hosts and have names resolve "correctly"
 
  


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

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

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