Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Repasting my answer from <a href="https://stackoverflow.com/questions/4809112/hosting-two-domains-using-only-one-vps/12654999#12654999">Hosting two domains using only one VPS?</a> as here it is even more relevant.</p> <p>As complete beginner, I have been trying to host multiple domains on one Apache VPS. Tutorials had too much information that lead me to confusion. </p> <p>Below I describe, for complete beginners, how to host multiple domains on one VPS server with Ubuntu and Apache.</p> <p><strong>IMPORTANT!</strong> You need to use root account to execute most operations.</p> <p><strong>IMPORTANT!</strong> If you have been trying to make some changes to apache configuration before, undo them.</p> <h2>Creating VirtualHosts</h2> <p>Create folders for your domains on server. For example:</p> <pre><code>/home/apache/domain1 /home/apache/domain2 </code></pre> <p>Put index.html file in each folder with any text.</p> <pre><code>This is domain1 This is domain2 </code></pre> <p>Go to <code>/etc/apache2/sites-available</code> folder.</p> <p>Create file domain1.conf</p> <pre><code>sudo nano domain1.conf &lt;VirtualHost *:80&gt; DocumentRoot /home/apache/domain1 ServerName domain1.com ServerAlias www.domain1.com &lt;/VirtualHost&gt; </code></pre> <p>Create file domain2.conf</p> <pre><code>sudo nano domain2.conf &lt;VirtualHost *:80&gt; DocumentRoot /home/apache/domain2 ServerName domain2.com ServerAlias www.domain2.com &lt;/VirtualHost&gt; </code></pre> <p>You can create subdomains same way.</p> <pre><code>sudo nano blog.conf &lt;VirtualHost *:80&gt; DocumentRoot /home/apache/blog ServerName blog.domain.com ServerAlias www.blog.domain.com &lt;/VirtualHost&gt; </code></pre> <p>Enable created sites</p> <pre><code>sudo a2ensite domain1.conf sudo a2ensite domain2.conf </code></pre> <p>Restart apache</p> <pre><code>sudo service apache2 reload </code></pre> <h2>Redirecting domain to server</h2> <p>Created VirtualHosts will work only if you redirect your domain name to server IP. Domains are just names that can be translated to IP numbers.</p> <h3>Local computer</h3> <p>To test your configuration on local machine, you need to edit hosts file.</p> <pre><code>sudo nano /etc/hosts </code></pre> <p>It should look like this.</p> <pre><code>127.0.0.1 localhost domain1.com domain2.com </code></pre> <p>Hosts file tells your computer that domain needs to be redirected to local machine.</p> <p><strong>IMPORTANT!</strong> If you create entry in hosts file for existing domain, for example</p> <pre><code>127.0.0.1 stackoverflow.com </code></pre> <p>you will loose access to this website.</p> <h3>Server</h3> <p>In order to redirect domain to you web server, you need to create or modify "A"-type DNS record for given domain to IP address of your server. You can do it by panel control provided by your domain registrar.</p> <p>If you do not know IP address of your server, log in to that server and type in command line:</p> <pre><code>ifconfig </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload