Host two websites in a single VPS

Asked

Viewed 621 times

0

I am trying to host two different websites in the same VPS. What are the right procedures to do this?

The server apache is already installed and I can host files there. However I can’t host two different sites.

Man 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 site 1...

  • You put the endereco2.com at gate 800 on purpose?

  • I don’t know much about servers. I put it on 800 believing that I could access 123.4.5.6:800 for the second site as follows. But without satisfactory results...

  • You left the Apache after making the change?

  • I suggest you leave the two at port 80 for easy access but to test you can not forget to configure the DNS or your file hosts for local testing.

  • Yes, yes, over and over again. I followed the steps of this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-6 The only thing I didn’t do was "Optional Step Six-Setting Up the Local Hosts". I’ll test here if that would be the problem then.

  • The reason I skipped this step is that in the tutorial they say that if I had redirected my domain to the VPS IP I could skip that step. And I rerouted both addresses to the VPS. @Edit: I updated the code, and I changed both to port 80, both with <Virtualhost *:80> But still no results...

  • I usually do it another way using sites-available and sites-enabled. Want me to post this solution as an answer for you to test?

  • 1

    Of course, all solutions are welcome.

Show 3 more comments

1 answer

1


Inside the directory of Apache there’s a directory called sites-available, in it there is an example called 000-default.conf.

To add new websites create two copies of this file: 010-site1.conf and 020-site2.conf (or the name you prefer) and within it enter the Virtual Hosts.

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 tool a2ensite:

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

Or simply 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 the Apache

sudo service apache2 restart
  • The Apache directory would be the right httpd folder? If so, I went to it and there is no such folder. I noticed that you suggested me to restart Apache using "apache2", but VPS uses a Linux Red Hat distribution (I don’t know if this influences anything, but I found it relevant to quote) but to restart apache I use "sudo /usr/sbin/httpd -k Restart". Could I create this folder "sites-available" with mkdir?

  • 1

    In some distros the Apache2 flame httpd. Directories must be /etc/httpd/sites-available and /etc/httpd/sites-enabled but apparently you have to add a line include ../sites-enabled inside /etc/httpd/conf/httpd.conf then just create the symbolic link and reload using service httpd reload.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.