0

Is it possible to setup a subdomain to point to a specific directory in apache2? I would like www.raspbianserver.com to point to /var/www/htdocs/index.html and backend.raspbianserver.com to point to /var/www/backend/backend.php

My current config file is

 <VirtualHost *:80>
    ServerAdmin info@anatak.com
    ServerName www.raspbianserver.com
    ServerAlias raspbianserver.com
    Redirect / https://raspbianserver.com

    DirectoryIndex index.html
    DocumentRoot /var/www/www.raspbianserver.com/htdocs/
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>

    <Directory /var/www/www.raspbianserver.com>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /var/www/www.raspbianserver.com/cgi-bin/
    <Directory "/var/www/www.raspbianserver.com/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog /var/www/www.raspbianserver.com/logs/error.log
    CustomLog /var/www/www.raspbianserver.com/logs/access.log combined

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

closed as off-topic by Morgan Courbet, Ghanima, Jacobm001, Bex, joan Feb 26 '15 at 20:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – Morgan Courbet, Ghanima, Jacobm001, Bex, joan
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    This is not the full config file, and it is not all the config files. There are numerous peculiarities in it. What did you try so far? What resources have you researched? – Bex Oct 3 '14 at 8:38
1

This page has a really nice tutorial on setting up multiple virtual hosts.

Basically you need a <VirtualHost *:80 > entry for each domain. Changing the ServerName and ServerAlias as required. Ideally, you'd keep these in separate files as it makes things nicer if you need to enhance one of them; for example if you wanted to proxy to an application server of some sort.

0

As Raspbian (I assume you use that) is a Debian distribution you should copy /etc/apache2/sites-available/000-default.conf to /etc/apache2/sites-available/www.rasbianserver.com.conf and change the contents of that file to suit your needs.

Things you would like to change are which IP-addresses/interfaces to use (Like *:80 in VirtualHost), domain-name of the server (like ServerName and ServerAlias) and where the files are stored (like DocumentRoot) the locations of the access and error logs (CustomLog and ErrorLog to /var/log/www/www.raspbinaserver.com-access.log and -error.lot) etc. I usually put them under the directory /srv/www as the directory /srv is supposed to be server data files. But anywhere you like will do, as long as you use a system. Dont forget to set up the file rights and user/group for wherever you choose.

The when you have it set up the way you like, you need to enable the server, and that is done with the command a2esite:

sudo a2ensite www.rasbianserver.com.conf
sudo service apache2 restart

or what a2ensite tells you to do. You could also open another terminal window on your machine and there write this command to see what you get when starting and accessing the server.

tail -f /var/log/apache2/www.rasbianserver.com-{access,error}.log

If you add yourself to the group adm you can look into logs without the need of sudo to the tail command. If you need to activate modules, you install the right package and then use a2enmod command. For more information, see man a2enmod, man a2ensite and man a2enconf. Also look in Debian Wiki and The Debian Administrator's Handbook.

Not the answer you're looking for? Browse other questions tagged or ask your own question.