Host two websites in a single VPS

0

I'm trying to host two different websites in the same VPS. What are the correct procedures for doing this?

The apache server is already installed and I can host files there. But I can not host two different websites.

My httpd.conf has the following:

NameVirtualHost *:80

<VirtualHost *:80>
     ServerAdmin primeiro_site@primeiro_site.com
     DocumentRoot /var/www/primeiro_site/public_html
     ServerName www.endereco1.com
     ServerAlias endereco1.com
     ErrorLog /var/www/primeiro_site/error.log
</VirtualHost>

<VirtualHost *:800>
     ServerAdmin [email protected]
     DocumentRoot /var/www/segundo_site/public_html
     ServerName www.endereco2.com
     ServerAlias endereco2.com
     ErrorLog /var/www/segundo_site/error.log
</VirtualHost>

But both addresses redirect to the folder of site 1 ...

    
asked by anonymous 08.01.2015 / 18:43

1 answer

1

Within the Apache directory there is a directory named sites-available , in it there is an example called 000-default.conf .

To add new sites create two copies of this file: 010-site1.conf and 020-site2.conf (or whatever name you prefer) and insert Virtual Hosts into it.

010-site1.conf

<VirtualHost *:80>
     ServerAdmin primeiro_site@primeiro_site.com
     DocumentRoot /var/www/primeiro_site/public_html
     ServerName www.endereco1.com
     ServerAlias endereco1.com
     ErrorLog /var/www/primeiro_site/error.log
</VirtualHost>

020-site2.conf

<VirtualHost *:80>
     ServerAdmin [email protected]
     DocumentRoot /var/www/segundo_site/public_html
     ServerName www.endereco2.com
     ServerAlias endereco2.com
     ErrorLog /var/www/segundo_site/error.log
</VirtualHost>

To activate use the a2ensite tool:

sudo a2ensite 010-site1.conf
sudo a2ensite 020-site1.conf

Or just create a symbolic link in sites-enabled for these two files:

ln -s 010-site1.conf ../sites-enabled/010-site1.conf
ln -s 020-site2.conf ../sites-enabled/020-site2.conf

For the changes to be applied it is necessary to restart Apache

sudo service apache2 restart
    
08.01.2015 / 19:16