Multiple Domains point to Different Directory

Hello,

Lets assume I am running Linode Debian 4.0 with Apache MySql & PHP. How would I configure my box to support multiple domains?

I was able to do this on several VPS's I have used in the past, but it was via some form of control panel.

For example:

www.testing123.net points to /home/testing123.net

www.example2.com points to /home/example2.com

www.apecraisins.org points to /home/apecraisins.org

Thanks!

13 Replies

http://httpd.apache.org/docs/2.0/vhosts/

Or you could give this a go.

http://www.linode.com/wiki/index.php/User:Kangaby

@mwalling:

http://httpd.apache.org/docs/2.0/vhosts/
Nice reading material!

> Or you could give this a go.

http://www.linode.com/wiki/index.php/User:Kangaby
Ahha! This is perfect, I will be reviewing every detail of this resource.

kangaby,

I ran into a problem on your wiki.

This is how I configured the default file.

(my website ip address is 67.18.186.137)

#/etc/apache2/sites-available/default

NameVirtualHost 67.18.186.137:80
 <virtualhost 67.18.186.137:80="">ServerAdmin root@triptoy.net

    DocumentRoot /var/www/
     <directory>Options FollowSymLinks
        AllowOverride None</directory> 

     <directory var="" www="">Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
        # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                # RedirectMatch ^/$ /apache2-default/</directory> 

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
     <directory "="" usr="" lib="" cgi-bin"="">AllowOverride None
        Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all</directory> 

    ErrorLog /var/log/apache2/error.log

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

    CustomLog /var/log/apache2/access.log combined
    ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <directory "="" usr="" share="" doc="">Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128</directory></virtualhost> 

I then configured these two files in the same directory as default, yet for some reason both domains still point to my /var/www

# /etc/apache2/sites-available/triptoy.net

 <virtualhost 67.18.186.137:80="">ServerName triptoy.net
 ServerAlias www.triptoy.net
 DocumentRoot "/home/triptoy.net/public_html"
 ScriptAlias /cgi-bin/ /home/triptoy.net/cgi-bin/</virtualhost> 

# /etc/apache2/sites-available/slivovitzmusic.com

 <virtualhost 67.18.186.137:80="">ServerName slivovitzmusic.com
 ServerAlias www.slivovitzmusic.com
 DocumentRoot "/home/slivovitzmusic.com/public_html"
 ScriptAlias /cgi-bin/ /home/slivovitzmusic.com/cgi-bin/</virtualhost> 

They look ok to me, and yes they are all opening the same content.

Have you restarted Apache, etc/init.d/apache2 restart since setting up the virtual hosts?

I suspect not, as it is not mentioned in the tutorial. When I did my setup, I set everything first and then restarted apache.

Edit: It is now. :D

I reloaded it twice, yet I have not tried rebooting the server. I have to head out for work, but I'll try again when I get home.

Thanks

Did you:

a2ensite triptoy.net && a2ensite slivovitzmusic.com 

?

@OverlordQ:

Did you:

a2ensite triptoy.net && a2ensite slivovitzmusic.com 

?

I've added this as well. That's the problem when you go from Apache 1 to Apache 2 and don't write every single thing down.

AFAIK, if you are using the sites-available/ file layout for httpd, you also need to create symlinks to those files from sites-enabled as that is where apache actually gets the files to load.

mwalling,

That's what I always do: set up the symlinks in sites-enabled manually. But I believe that's exactly what the a2ensite tool does.

Should I comment out "DocumentRoot /var/www/" in the default file if I have a file for every website in the directory?

Or point it to a sub-directory of /var/www/ if you like

@Xan:

mwalling,

But I believe that's exactly what the a2ensite tool does.

That's what it does. There are a2en* and a2dis* for sites and modules.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct