View Full Version : apache2 with multiple directories

August 22nd, 2010, 09:30 AM
Apache2 default directory is /var/ww. Is it possible to add one more directory(/usr/share/tomcat/webapps) to apache config.? so that i can have both /var/www as well as /usr/share/tomcat/webapps

Thank you all!

Lars Noodén
August 23rd, 2010, 06:45 PM
Yes. There are several ways to do that. One is to make use of the runtime directives, directory (http://httpd.apache.org/docs/2.3/mod/core.html#directory) and, maybe, alias (http://httpd.apache.org/docs/2.3/mod/mod_alias.html#alias).

August 27th, 2010, 02:49 PM
Please any one show me how to do this without any errors..

August 27th, 2010, 07:16 PM
I just use vhosts.

Create a file in /etc/apache2/sites-available for each subdomain you'd like to host and then enable those domains.

This is a very simple example for hostname website and would be located at /etc/apache2/sites-available/website

<VirtualHost *:80>
ServerName www.domain.com
DocumentRoot /var/www/website/public/

This is an SSL site located at /etc/apache2/sites-available/ecommerce

<Virtualhost *:443>
ServerName ecommerce.domain.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/ecommerce.domain.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/ecommerce.domain.com.key
DocumentRoot /var/www/ecommerce/public/

I like to add this to the bottom of my /etc/apache2/apache2.conf file so that traffic gets compressed and I set expires headers...

# GZIP files
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE <img src="no-gzip" alt="" />gzip-only-text/html

# Expire Headers
ExpiresActive On
ExpiresDefault "access plus 10 years"

To enable a website just type...

a2ensite website


a2ensite ecommerce

Then, restart apache

/etc/init.d/apache2 restart

Doing this, you can add many different directories to host websites (although, I'd recommend putting all your created apps in /var/www, that's the default).

Just make sure they are owned by www-data with the correct permissions...

chown -R www-data:www-data /var/www
chmod -R 755 /var/www

Hope that helps.