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.

1 Answer 1

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 [email protected]
    <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 [email protected]
    <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.

2
  • Thank you for the answer. I'm using an Apache server. Should I really define ScriptAlias? Jan 18, 2014 at 19:44
  • 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
    Jan 19, 2014 at 2:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .