LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Query: CentOS 6.2 Apache 2.2.15 Virtual Host Set-up (http://www.linuxquestions.org/questions/linux-server-73/query-centos-6-2-apache-2-2-15-virtual-host-set-up-932359/)

LouArnold 03-02-2012 12:02 PM

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>


slugmax 03-02-2012 12:18 PM

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

LouArnold 03-02-2012 01:42 PM

Quote:

Originally Posted by slugmax (Post 4616976)
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.

LouArnold 03-02-2012 02:27 PM

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

slugmax 03-02-2012 02:34 PM

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

slugmax 03-02-2012 02:37 PM

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.

LouArnold 03-02-2012 03:29 PM

Quote:

Originally Posted by slugmax (Post 4617055)
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.

LouArnold 03-02-2012 04:12 PM

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.

LouArnold 03-02-2012 04:42 PM

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>


slugmax 03-02-2012 05:21 PM

Quote:

Originally Posted by LouArnold (Post 4617091)
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


slugmax 03-02-2012 05:34 PM

Quote:

Originally Posted by LouArnold (Post 4617124)
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).

LouArnold 03-02-2012 07:10 PM

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.


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