How to use various sites in Ubuntu Dedicated Server?

0

Hello, friends!

Context: I have a dedicated server to host web applications.

  • The root directory is the default / var / www / html of any server.
  • I want to host a website first.
  • In the root directory (/ var / www / html) is phpmyadmin and the site
  • I'm updating the site files via GIT, ie it has to stay in a separate folder, in this case the "site" folder. And also to use the GIT pull and do not give problem with the folder phpmyadmin

Problem: The problem is that ALL files that I call externally are coming from root,

<link href="/css/style.css">

That is, it is calling the following path:

/var/www/html/css/style.css

You have the solutions to add the site folder, as follows:

<link href="/site/css/style.css">

But that's not the proposal. If you did, you would have to change everything in one whole application and it would be harder to work locally and collaborate with other people.

Question: I would like to know the right way to do this and to work in the future with more sites and folders within / var / www / html, without changing the path all the application and damaging the operation of git ?

Considerations: If it was not clear enough, please let me know that I'll try to get more detailed!

    
asked by anonymous 12.02.2018 / 16:02

1 answer

1

To host several applications on a server you need to configure VirtualHosts in Apache.

With this, you have a site in each folder and points each of the domains to a different DirectoryRoot.

Creating a configuration file for siteA. This file should stay in /etc/apache2/sites-available/sitea.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName sitea.com.br
    DocumentRoot /var/www/sitea/public
    ErrorLog ${APACHE_LOG_DIR}/sitea-error.log
    CustomLog ${APACHE_LOG_DIR}/sitea-access.log combined
</VirtualHost>

Create the folder and upload the sitea to /var/www/sitea/public as defined in the DocumentRoot

Now point your domain (sitea.com.br in the example) to the IP of this server.

And enable the website with the command a2ensite sitea . Remember that this command expects to receive the name of the configuration file that is in the /etc/apache2/sites-available

Repeat the process for as many VirtualHosts as you need.

Ah! And, if you need a subdomain you can use as many as you want with the ServerAlias configuration, but do not forget to configure the DNS zone for your domain. Example:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName sitea.com.br
    ServerAlias www.sitea.com.br teste.sitea.com.br
    DocumentRoot /var/www/sitea/public
    ErrorLog ${APACHE_LOG_DIR}/sitea-error.log
    CustomLog ${APACHE_LOG_DIR}/sitea-access.log combined
</VirtualHost>

See this tutorial: link

    
12.02.2018 / 16:40