Forward two different websites to the same server

1

1

I'm pretty new in webserver management. So I rented this server, and setup a LAMP server with MySql and everything is alright in that sense.

The problem is now that I have two different domains (say www.domain1.com, www.domain2.org), and I want each of them to load the website content from a different folder on my server.

How can I do that?

I tried to google some relevant terms, but I couldn't find what that's called.

Thank you for any efforts.

The Quantum Physicist

Posted 2014-01-18T16:52:33.027

Reputation: 648

Answers

2

Use VirtualHosts in your httpd.conf. Also, make sure the DNS configuration points both domains to the same server. For example:

<VirtualHost *:80>
    DocumentRoot /path/to/domain1.com/html
    ServerName www.domain1.com
    ScriptAlias /cgi-bin/ /path/to/domain1.com/cgi-bin
    <Directory "/path/to/domain1.com/cgi-bin">
        Options ExecCGI
    </Directory>

    ServerAdmin youremail@adress.com
    <Directory "/path/to/domain1.com/html">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /path/to/domain2.org/html
    ServerName www.domain2.org
    ScriptAlias /cgi-bin/ /path/to/domain2.org/cgi-bin
    <Directory "/path/to/domain2.org/cgi-bin">
        Options ExecCGI
    </Directory>

    ServerAdmin youremail@adress.com
    <Directory "/path/to/domain2.org/html">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

Hope this helps!

EDIT

Here is a minimal virtualhost entry (you can put multiple entries in one httpd.conf file):

<VirtualHost *:80>
    DocumentRoot /path/to/website.com/html
    ServerName www.website.com
    <Directory "/path/to/website.com/html">
        Require all granted
    </Directory>
</VirtualHost>

That (to my understanding) is the minimum required information for a VirtualHost. If any one knows otherwise, go ahead and let me know/edit the question.

BenjiWiebe

Posted 2014-01-18T16:52:33.027

Reputation: 7 672

Thank you for the answer. I'm using an Apache server. Should I really define ScriptAlias? – The Quantum Physicist – 2014-01-18T19:44:55.123

If you have want a www.domainname.com/cgi-bin/ directory. Otherwise, it isn't necessary. I'll update the question with a "minimum" vhost entry. – BenjiWiebe – 2014-01-19T02:09:16.563