2 Domains on 1 server

Solution 1:

Assuming you are talking about configuring an HTTP Server, and that it is Apache, in Debian, VirtualHosts are managed in directory /etc/www/apache2/sites-available. You create a text file here, with whichever name you want (it is good practice to use the same as the domain you are about to configure).

Lets say you have site1.com. You create the file /etc/www/apache2/sites-available/site1.com with the following contents:

<VirtualHost *:80>
  ServerName  site1.com
  ServerAlias www.site1.com 

  DocumentRoot /var/www/site1.com

  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>

  <Directory /var/www/sigma/html>
    Options FollowSymLinks MultiViews
    Order allow,deny
    allow from all
  </Directory>

  LogLevel warn
  CustomLog /var/log/apache2/site1.com/access.log combined
  ErrorLog  /var/log/apache2/site1.com/error.log

</virtualHost>

The you create a symlink on /etc/www/apache2/sites-enabled like this:

# cd /etc/www/apache2/sites-enabled
# ln -s ../sites-available/site1.com 000-site1.com

This sets up your first virtual server. If you want to have site2.com copy this file to another one named after this new domain and change the parameter accordingly:

  • ServerName
  • ServerAlias
  • DocumentRoot
  • Directory
  • CustomLog
  • ErrorLog

Create the proper symlink and reload apache (/etc/init.d/apache2 reload)

You will have by default a file /etc/apache2/sites-available/default which sets the default virtual host for apache. That is solely because it is loaded first as /etc/apache2/sites-enabled/000-default. It is just another virtual host.

As far as DNS records, you can just point site2.com to the same address to which is pointed site1.com.

There is much more to this configuration options, which you can read at the official Apache HTTP server documentation.

EDIT:

cgi-bin directory is just described as another directive on each virtualhost. Just add to site1.com configuration file something like:

ScriptAlias /cgi-bin/ /some/path/to/site1/cgi-bin

And to site2.com config file:

ScriptAlias /cgi-bin/ /some/path/to/site2/cgi-bin

Or you can even share the same directory for both servers. More on configuring CGI on apache

Solution 2:

I'm going to assume you're using Apache as your web server. If so, you are looking to implement Virtual Hosts - two (or more) domains, one IP.

Here are some nice tutorials to get you started...