Search code examples
configurationapache2directorydefault

Which parts of the apache sites-available file are necessary?


I noticed that the default sites-available file (/etc/apache2/sites-available/default) contained many "directory" tags with various options.

<Directory />, <Directory /var/www/>, <Directory "/usr/lib/cgi-bin">, and <Directory "/usr/share/doc/">

Do I need any of those, or can I safely remove them?


Solution

  • Don't start adjusting the default site, it will just become a mess and you won't be able to figure out what directive does what.
    I would recommend you write your own virtual host configuration, this way you actually know what your site does. Here is a little bare bones configuration to get you started.

    <VirtualHost *:80>
        ServerName www.mywebsite.com
        DocumentRoot /home/www/public_html/
        <Directory /home/www/public_html/>
            Options None
            Order deny,allow
            Allow from all
        </Directory>
    </VirtualHost>
    

    Just put it in sites-available and then run a2ensite mywebsite (mywebsite being the filename of the vhost configuration), then reload the server configuration with /etc/init.d/apache2 reload.
    An explanation for all the directives I used can be found in the apache documentation (I am assuming you run version 2.2).

    Oh, and of course you need to disable the default site (a2dissite default) if the ServerNames are conflicting.