Jump to content
inittux

Don't understand something about virtualhosts

Recommended Posts

I'm trying to get virtual hosts working on Apache.

 

In /etc/httpd/conf/http.conf it says that: DocumentRoot "/var/www/html". So I think that's the place where Apache will be looking for your website files.

 

I made a virtualhost:

 

NameVirtualHost ipadress:80

 

# Custom virtualhosts

 

ServerAlias www.feedmebits.nl

ServerAdmin maarten@feedmebits.nl

DocumentRoot feedmebits.nl

ServerName feedmebits.nl

ErrorLog logs/feedmebits.nl-error_log

#CustomLog logs/host.some_domain.com-access_log common

 

in /var/www/html/ I made two directories so it looks like this:

/var/www/html/websites/feedmebits.nl

 

 

When I restart Apached it restarts but gives me an error:

Starting httpd: Warning: DocumentRoot [/etc/httpd/feedmebits.nl] does not exist

 

When I try and make a directory in /etc/httpd/feedmebits.nl and restart apache I don't get the error message.

And when I try making putting feedmebits.nl in a sub directory: /etc/httpd/websites/feedmebits.nl I also get

an the same error message.

I don't quite understand this because isn't it supposed to go to DocumentRoot which is /var/www/html and if I added

directories in there and mentioned it in my virtual host, isn't it supposed to see it? Why am I getting an error?

Don't quite understand?

 

Another thing I noticed, is that when I have my virtualhost enabled, and try to go to my test.php which is in /var/www/html/test.php

It doesn't work anymore either. When I add it to /etc/httpd/feedmebits.nl, it works again.

Share this post


Link to post
Share on other sites

Something I discovered if I change the DocumentRoot it works.

 

# Custom virtualhosts

 

ServerAlias www.feedmebits.nl

ServerAdmin maarten@feedmebits.nl

DocumentRoot feedmebits.nl

ServerName feedmebits.nl

ErrorLog logs/feedmebits.nl-error_log

#CustomLog logs/host.some_domain.com-access_log common

 

DocumentRoot /var/www/html/websites/feedmebits.nl

 

 

I discovered in the /etc/http/conf/httpd.conf file that /etc/httpd is the serverroot directory path.

So I probably shouldn't put any website/data/directories there.

 

ServerRoot "/etc/httpd"

 

 

So I'm still trying to understand why in my virtualhost Document Root I have to

give the full path /var/www/html/websites/feedmebits.nl instead of just /websites/feedmebits.nl

because DocumentRoot is set to DocumentRoot "/var/www/html" in http.conf?

Share this post


Link to post
Share on other sites

Something I discovered if I change the DocumentRoot it works.

 

# Custom virtualhosts

 

ServerAlias www.feedmebits.nl

ServerAdmin maarten@feedmebits.nl

DocumentRoot feedmebits.nl

ServerName feedmebits.nl

ErrorLog logs/feedmebits.nl-error_log

#CustomLog logs/host.some_domain.com-access_log common

 

DocumentRoot /var/www/html/websites/feedmebits.nl

 

 

I discovered in the /etc/http/conf/httpd.conf file that /etc/httpd is the serverroot directory path.

So I probably shouldn't put any website/data/directories there.

 

ServerRoot "/etc/httpd"

 

 

So I'm still trying to understand why in my virtualhost Document Root I have to

give the full path /var/www/html/websites/feedmebits.nl instead of just /websites/feedmebits.nl

because DocumentRoot is set to DocumentRoot "/var/www/html" in http.conf?

 

 

Well I left it like that for now giving the full DocumentRoot for the virtualhost and it's working

Share this post


Link to post
Share on other sites

I realise you've already answered your own question here, but I wanted to just chime in that my Apache virtual hosts configuration has the full paths for the DocumentRoot declarations. Glad your virtual hosts are working.

Share this post


Link to post
Share on other sites

I realise you've already answered your own question here, but I wanted to just chime in that my Apache virtual hosts configuration has the full paths for the DocumentRoot declarations. Glad your virtual hosts are working.

 

Thanks for your reply. Been playing around with apache and trying out different things. It's been a while, glad you are back :)

Share this post


Link to post
Share on other sites
Thanks for your reply. Been playing around with apache and trying out different things. It's been a while, glad you are back

 

Yeah, I've been really really busy working on a project for a couple of weeks and haven't had the time to catch up here!

Share this post


Link to post
Share on other sites

ServerRoot should be mentioned ONCE in the main httpd.conf file and is the root dir for which all relative paths originate from.

 

If you have the following:

ServerRoot /etc/httpd
DocumentRoot mysite

Then Apache looks for /etc/httpd/mysite for your "index.html" file.

 

When configuring Vhosts, it's safer to use absolute paths for the DocumentRoot and logfile locations.

 

nb: Your ServerName *should* come before the ServerAlias, since ServerName is what the site is primarily known as. ServerAlias are alternative names.

Share this post


Link to post
Share on other sites

ServerRoot should be mentioned ONCE in the main httpd.conf file and is the root dir for which all relative paths originate from.

 

If you have the following:

ServerRoot /etc/httpd
DocumentRoot mysite

Then Apache looks for /etc/httpd/mysite for your "index.html" file.

 

When configuring Vhosts, it's safer to use absolute paths for the DocumentRoot and logfile locations.

 

nb: Your ServerName *should* come before the ServerAlias, since ServerName is what the site is primarily known as. ServerAlias are alternative names.

 

I changed my DocumentRoot to /home/feedmebits/www

I have my ServerName before my ServerAlias now

And I put feedmebits.net as another alias now and I restarted apache.

 

And I changed my config file to:

 

 

 

ServerName feedmebits.com

ServerAlias feedmebits.nl feedmebits.com feedmebits.net feedmebits.testing

ServerAdmin maarten@feedmebits.nl

DocumentRoot /home/feedmebits/www/feedmebits.nl

ErrorLog /var/log/httpd/websites/feedmebits.nl/error.log

CustomLog /var/log/httpd/websites/feedmebits.nl/access.log combined

 

AllowOverride None

order allow,deny

allow from all

Options Indexes Includes FollowSymLinks

I still get forbidden for feedmebits.com and I get the same for feedmebits.net now so that part works now :)

Share this post


Link to post
Share on other sites

ServerRoot should be mentioned ONCE in the main httpd.conf file and is the root dir for which all relative paths originate from.

 

If you have the following:

ServerRoot /etc/httpd
DocumentRoot mysite

Then Apache looks for /etc/httpd/mysite for your "index.html" file.

 

When configuring Vhosts, it's safer to use absolute paths for the DocumentRoot and logfile locations.

 

nb: Your ServerName *should* come before the ServerAlias, since ServerName is what the site is primarily known as. ServerAlias are alternative names.

 

I got everything except my index.html file. I tried change the ServerRoot file but I get an error. Going to try out some more things to see what happens.

Share this post


Link to post
Share on other sites

nooo! ServerRoot is the directory that is prepended to all RELATIVE paths - if you change that, you'll have to go through and change all your paths to modules, includes, external configs, etc. Best leave that part alone!

 

It *does* look like you're missing a "DirectoryIndex" directive in your container that points to your index page - may want to pop that in:

 

<Directory /home/feedmebits/www/feedmebits.nl/>
AllowOverride None
order allow,deny
allow from all
Options Indexes Includes FollowSymLinks
DirectoryIndex index.html
</Directory>

Share this post


Link to post
Share on other sites

nooo! ServerRoot is the directory that is prepended to all RELATIVE paths - if you change that, you'll have to go through and change all your paths to modules, includes, external configs, etc. Best leave that part alone!

 

It *does* look like you're missing a "DirectoryIndex" directive in your container that points to your index page - may want to pop that in:

 

<Directory /home/feedmebits/www/feedmebits.nl/>
AllowOverride None
order allow,deny
allow from all
Options Indexes Includes FollowSymLinks
DirectoryIndex index.html
</Directory>

 

Thanks for that little detail. Yeah I changed it back as soon after I tried cuz I was getting errors that certain modules etc couldn't be loaded :P

Share this post


Link to post
Share on other sites
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...