LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-02-2012, 11:02 AM   #1
LouArnold
Member
 
Registered: Mar 2006
Distribution: Linux Mint 18.1 w/Cinnamon
Posts: 75

Rep: Reputation: 15
Query: CentOS 6.2 Apache 2.2.15 Virtual Host Set-up


I've tried to set up a virtual host under Apache and I think I have some success, but I need to ask:

When I type a URL that includes the index file name, I get the proper web page. (http://xDrupalDocs.com/index.html).
But when I just type in the domain name (http://xDrupalDocs.com), I get an error page from my ISP. Is this the proper behaviour?

I've tried using the physical IP of the machine in place of the "*", but I get the same results.

Here are the files:
I omitted the domain name entirely in the /etc/hosts file.

httpd.conf:
Code:
#NameVirtualHost 192.168.1.149:80
NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot /var/www/html
   ServerName localhost
</VirtualHost>

#<VirtualHost 192.168.1.149:80>
<VirtualHost *:80>
	DocumentRoot /home/DrupalDocs/htdocs
	ServerName xDrupalDocs.com
	<Directory "/home/DrupalDocs/htdocs">
	    Options Includes FollowSymLinks
		AllowOverride All
		allow from all
		Options +Indexes
	</Directory>
	ServerAlias *.xDrupalDocs.com
	ErrorLog /home/DrupalDocs/htdocs/DrupalDocsErrorLog.log
	LogLevel emerg
	UseCanonicalName off
</VirtualHost>
 
Old 03-02-2012, 11:18 AM   #2
thinknix
Member
 
Registered: Nov 2008
Distribution: Lots!
Posts: 178

Rep: Reputation: 58
You should have a DirectoryIndex directive in your httpd.conf, so you would add index.html to that, but if not you can add it to your virtual host definition, just after the line '<Directory "/home/DrupalDocs/htdocs">':

Code:
DirectoryIndex index.html
 
Old 03-02-2012, 12:42 PM   #3
LouArnold
Member
 
Registered: Mar 2006
Distribution: Linux Mint 18.1 w/Cinnamon
Posts: 75

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by slugmax View Post
You should have a DirectoryIndex directive in your httpd.conf, so you would add index.html to that, but if not you can add it to your virtual host definition, just after the line '<Directory "/home/DrupalDocs/htdocs">':

Code:
DirectoryIndex index.html
That doesn't appear to work:
- There was already such a line in the httpd.conf file.
- Adding the line under the <Directory> directive caused the display of the ISP's error page regardless of whether "xDrupalDocs.com/index.html" or simply "xDrupalDocs.com" was entered as a URL.
- Removing all the DirectoryIndex directives also produces the ISP's error page regardless of the entry.
- Same result if the outer directive is removed and only the inner directive is kept.

Last edited by LouArnold; 03-02-2012 at 12:49 PM.
 
Old 03-02-2012, 01:27 PM   #4
LouArnold
Member
 
Registered: Mar 2006
Distribution: Linux Mint 18.1 w/Cinnamon
Posts: 75

Original Poster
Rep: Reputation: 15
Ahhh...now I'm in trouble. All the results changed when I undid the DirectoryIndex directive changes. Only one exists in the file, but now this is what happens:
- www.xDrupalDocs.com and xDrupalDocs.com/index.html go to the ISP error page.
- xDrupalDocs.com goes to the default web page for Apache (var/www/html/index.html
 
Old 03-02-2012, 01:34 PM   #5
thinknix
Member
 
Registered: Nov 2008
Distribution: Lots!
Posts: 178

Rep: Reputation: 58
You mention your ISPs error page - do you know the actual HTTP error code returned?

Also, I notice you have two separate Options lines - I would combine them into one, without mixing the '+' and non-'+' options, so it looks like this:

Code:
Options +Includes +FollowSymLinks +Indexes
or

Code:
Options Includes FollowSymLinks Indexes
 
Old 03-02-2012, 01:37 PM   #6
thinknix
Member
 
Registered: Nov 2008
Distribution: Lots!
Posts: 178

Rep: Reputation: 58
I would also add, since you already have a DirectoryIndex line in your httpd.conf that specifies index.html, take it out of your vhost definition.
 
Old 03-02-2012, 02:29 PM   #7
LouArnold
Member
 
Registered: Mar 2006
Distribution: Linux Mint 18.1 w/Cinnamon
Posts: 75

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by slugmax View Post
I would also add, since you already have a DirectoryIndex line in your httpd.conf that specifies index.html, take it out of your vhost definition.
- Done

The ISP error page is a large list of ads really, but has no error number. It says: "We did not find results for: www.xdrupaldocs.com".

Here is the httpd.conf file:
Code:
#NameVirtualHost 192.168.1.149:80
NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot /var/www/html
   ServerName localhost
</VirtualHost>

#<VirtualHost 192.168.1.149:80>
<VirtualHost *:80>
	DocumentRoot /home/DrupalDocs/htdocs
	ServerName xDrupalDocs.com
	<Directory "/home/DrupalDocs/htdocs">
	   	Options Includes FollowSymLinks Indexes
		AllowOverride All
		allow from all
	</Directory>
	ServerAlias *.xDrupalDocs.com
	ErrorLog /home/DrupalDocs/htdocs/DrupalDocsErrorLog.log
	LogLevel emerg
	UseCanonicalName off
</VirtualHost>
Now the test results are:
- www.xdrupaldocs.com and www.xdrupaldocs.com/index.html - bring up the ISP error page.
- xdrupaldocs.com/index.html brings up /home/DrupalDocs/htdocs/index.html - this is the desired result.
- simply xdrupaldocs.com - brings up the default Apache page /var/www/html/index.html.

This is the original behaviour; I don't understand why it changed and then reverted back.
I was careful to restart httpd in each case.

Last edited by LouArnold; 03-02-2012 at 02:31 PM.
 
Old 03-02-2012, 03:12 PM   #8
LouArnold
Member
 
Registered: Mar 2006
Distribution: Linux Mint 18.1 w/Cinnamon
Posts: 75

Original Poster
Rep: Reputation: 15
Just to show you how dumb things get sometimes, I followed this guide: http://linuxconfig.org/configure-apa...host-on-fedora
Here are the steps:

Step 1:Create a directory to contain your new website:
# mkdir /var/www/example.net
# echo Hello Web > /var/www/example.net/index.html
# chmod -R 755 /var/www/example.net
# chown -R apache.apache /var/www/example.net

Step 2: Add virtual host configuration to the bottom of /etc/httpd/conf/httpd.conf :
<VirtualHost *:80>
DocumentRoot /var/www/example.net
ServerName www.example.net
# Other Apache config directives, logs etc.
</VirtualHost>

Step 3: Confirm the VirtualHost sytax before restarting httpd service:
# httpd -S

Step 4: Restart apache :
# /etc/init.d/httpd restart

Step 5:
If your example domain is already pointing to your server you should be ready to go. Make sure that your domain resolves an IP address of your server. For testing it is also handy to modify /etc/hosts file. For example if this is done just locally add :
# echo 127.0.0.1 www.example.net example.net >> /etc/hosts

This is the end of the example.

I carried out the steps - exactly as you see them. With this exact VirtualHost definition.
<VirtualHost *:80>
DocumentRoot /var/www/example.net
ServerName www.example.net
# Other Apache config directives, logs etc.
</VirtualHost>

I then went to the browser and entered the URL www.example.net and it came up with the text "Hello Web" as set in step 1. It worked perfectly! So mine is just too complex. HAHAHAHA.

Seriously. I think it has to do with the domain name I chose; it must be a full normal name as in "www.domainname.com". I just chose "xDrupalDocs.com and not "www.xDrupalDocs.com". I'll try that.

Last edited by LouArnold; 03-02-2012 at 03:15 PM.
 
Old 03-02-2012, 03:42 PM   #9
LouArnold
Member
 
Registered: Mar 2006
Distribution: Linux Mint 18.1 w/Cinnamon
Posts: 75

Original Poster
Rep: Reputation: 15
OK. I tried it and here are some results:
There was a permissions problem. All the files from /home/DrupalDocs on into the tree had to have their owner and group changed to "apache". Also, their permissions had to be changed to 755 as in:
# chmod -R 755 /home/DrupalDocs
# chown -R apache.apache /home/DrupalDocs
Another important part was adding the domain names to the /etc/hosts file as the localhost IP of 127.0.0.1.

Just some notes, though.
- A URL of xdrupaldocs.com produces an ISP error page.
- Yet a URL of example.net brings up the default Apache web page.
This difference puzzles me.
The final httpd.conf excerpt is:
Code:
#NameVirtualHost 192.168.1.149:80
NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot /var/www/html
   ServerName localhost
</VirtualHost>

#<VirtualHost 192.168.1.149:80>
<VirtualHost *:80>
	DocumentRoot /home/DrupalDocs/htdocs
	ServerName www.xDrupalDocs.com
	<Directory "/home/DrupalDocs/htdocs">
	    Options Includes FollowSymLinks Indexes
		AllowOverride All
		allow from all
	</Directory>
	ServerAlias *.xDrupalDocs.com
	ErrorLog /home/DrupalDocs/htdocs/DrupalDocsErrorLog.log
	LogLevel emerg
	UseCanonicalName off
</VirtualHost>

# Taken from: http://linuxconfig.org/configure-apache-virtualhost-on-fedora
<VirtualHost *:80>
DocumentRoot /var/www/example.net
ServerName www.example.net
# Other Apache config directives, logs etc.
</VirtualHost>
 
Old 03-02-2012, 04:21 PM   #10
thinknix
Member
 
Registered: Nov 2008
Distribution: Lots!
Posts: 178

Rep: Reputation: 58
Quote:
Originally Posted by LouArnold View Post
The ISP error page is a large list of ads really, but has no error number. It says: "We did not find results for: www.xdrupaldocs.com".
...
Now the test results are:
- www.xdrupaldocs.com and www.xdrupaldocs.com/index.html - bring up the ISP error page.
- xdrupaldocs.com/index.html brings up /home/DrupalDocs/htdocs/index.html - this is the desired result.
- simply xdrupaldocs.com - brings up the default Apache page /var/www/html/index.html.
OK, that sounds like your ISP is intercepting your failed DNS queries. Do you have an A-record or cname for www in the domain xdrupaldocs.com? You can test this simply by running 'host www.xdrupaldocs.com 8.8.8.8' - this will query google's public DNS directly and tell you if that hostname can be found, circumventing your ISP's ad-trap.

Also, I don't think you can use wildcards in a ServerAlias. I would use this:

Code:
ServerName xDrupalDocs.com
ServerAlias www.xDrupalDocs.com
 
Old 03-02-2012, 04:34 PM   #11
thinknix
Member
 
Registered: Nov 2008
Distribution: Lots!
Posts: 178

Rep: Reputation: 58
Quote:
Originally Posted by LouArnold View Post
There was a permissions problem. All the files from /home/DrupalDocs on into the tree had to have their owner and group changed to "apache". Also, their permissions had to be changed to 755 as in:
# chmod -R 755 /home/DrupalDocs
# chown -R apache.apache /home/DrupalDocs
Permissions only matter here as far as allowing apache to read the files. Execute permissions would be needed only on CGIs or directories. A mode of 755 does allow apache (and anyone else) to read the files - but by changing the owner of these files to the user the web server runs under, you open a potential security hole. If anyone compromises your web server they will have read/write access to the files. So I would recommend changing the owner/group back to root, unless you need the read/write access by apache (sometimes the case with CMSs).
 
Old 03-02-2012, 06:10 PM   #12
LouArnold
Member
 
Registered: Mar 2006
Distribution: Linux Mint 18.1 w/Cinnamon
Posts: 75

Original Poster
Rep: Reputation: 15
I think you're right slugmax. But this is purely for my own home LAN use. I had planned just to try to build web sites and then move them to hosting company. The current goal was just to be able to install and use both Drupal and Joomla dn see how they work.

Thanks for your time.
I have to figure out how to mark the thread as solved.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set apache virtual hosts Host-Based Security? hocheetiong Linux - Newbie 2 01-17-2014 04:20 AM
Any way to tunnel apache virtual host to an internal apache? ciuly Linux - Server 5 01-31-2010 12:53 PM
centos 5: query regarding configuring svn with apache 2... deostroll Linux - Server 1 12-29-2009 09:25 PM
CentOS Apache Server - identifying (virtual host) target of spam attack Lord Matt Linux - Server 3 04-07-2008 02:17 AM
Apache Virtual Host query Atif_Khan Linux - Server 4 01-16-2007 05:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:10 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
Open Source Consulting | Domain Registration