LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Apache Virtual Host Document Root (https://www.linuxquestions.org/questions/linux-newbie-8/apache-virtual-host-document-root-753895/)

vertigo12369 09-09-2009 10:38 AM

Apache Virtual Host Document Root
 
Hi All,

I'm now configuring my web server to server different Virtual Hosts based on DNS name. Right now I store my files in /var/www per the default installation settings in Apache.

Questions:
I want to change the Document Root to /home/username/public_html/example1.dyndns.org for the second virtual server. What do the permissions need to be in order for Apache to read the files in this location? Would it be best to force Apache to run as this new username instead of www-data?

My Virtual host setup will look something like this

<VirtualHost *:80
DocumentRoot /var/www
ServerName default.dyndns.org
#Additional options here

</VirtualHost

<VirtualHost *:80
DocumentRoot /home/username/public_html/example1.dyndns.org
ServerName example1.dyndns.org
#Additional options here

</VirtualHost

I want to change the DocumentRoot as I am running a chrooted ProFTPd server and want to be able to update webserver files via FTP.

I hope this makes sense. I am running Ubuntu 8.04 LTS Server (CLI only).

Wim Sturkenboom 09-10-2009 03:02 AM

As long as apache can read the directory and files, it will be fine. Don't forget the below section if you get 403 errors.
Code:

#WimS
# this is required to prevent message 403 "Forbidden"
    <Directory "/home/wim/www/site1/web">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

My web applications need write permissions (by apache). I have allocated one 'standard' directory in each documentroot for this and did sort out the permissions using ACL so apache can indeed write there.

PS The documentroots for my virtual sites are in /home as shown below (from a Slackware box; I know ubuntu works slightly different).
Code:

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

# catch-all
<VirtualHost *:80>
    ServerAdmin me@mydomain
    DocumentRoot /srv/httpd/htdocs
    ServerName btd-techweb02
</VirtualHost>

# site 1
<VirtualHost *:80>
    ServerAdmin me@mydomain
    DocumentRoot /home/wim/www/site1/web
    ServerName site1.btd-techweb02
    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
    <Directory "/home/wim/www/site1/web">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

# site2
<VirtualHost *:80>
    ServerAdmin me@mydomain
    DocumentRoot /home/wim/www/site2/web
    ServerName site2.btd-techweb02
    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/httpd/access_log common

#WimS
# this is required to prevent message 403 "Forbidden"
    <Directory "/home/wim/www/site2/web">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>


Fill 09-10-2009 03:03 AM

Hi,

I would do this:

Code:

# cd /home/username
# mkdir public_html
# cd public_html
# mkdir example1.dyndns.org
# chown www-data example1.dyndns.org

That way, user www-data (or whoever you want to) would be able to write and read on the directory example1.dyndns.org, but not on public_html.

See ya

vertigo12369 09-10-2009 07:08 AM

Thanks, guys! I have it up an running, but it looks like I should add some lines to handle exceptions and fix some permissions.

Couple more questions I ran across when looking at some HowTos...

Is there anything that needs to be added to the main apache2.conf file to enable virtual hosts or can I just add sites to the /sites-available from a fresh install?

One article says I need to create a file...
/etc/apache2/conf.d/virtual.conf
and put the following statement in the file...

Code:

#  We're running multiple virtual hosts.
#
NameVirtualHost *
#

Another article says I need

Code:

NameVirtualHost <ip>:<Port Number>
In the /etc/apache2/apache2.conf file.


Now I added both of these statements, but noticed that I do the same thing in my virtual host files that are stored in /sites-enabled

What is the correct location to add these statements?

Wim Sturkenboom 09-10-2009 08:19 AM

If you use Ubuntu, stick to articles dedicated to Ubuntu. Do not read anything else as it more than likely does not apply and therefore will confuse you.

What I posted in #2 is the vhosts.conf file as used in Slackware 12 and that's the only place where NameVirtusalHost is used.


All times are GMT -5. The time now is 06:11 AM.