There is a VPS on which LAMP stands. And only 2 directories wp1 and wp2. I need to bind the site.com domain to the wp1 folder, and site.ru to the wp2 folder. But at the domain registrar I can register only the IP address of the VPS. I can’t insert a record like 105.170.98.108/wp1/. How do I properly configure Apache in my case?

    2 answers 2

    A very common question, and the above is absolutely correct - you need to use virtual hosts. I would like to give my configuration, which I consider the most convenient.

    Judging by the name of directories, you have wordpress. What are the difficulties from which you can not run away. These difficulties are security holes, and it is better for a novice to save up experience before setting up a combat server, otherwise the probability of giving a server to hackers is very high.

    Config vHost:

    <VirtualHost *:80> DocumentRoot "/home/hh-upper/public_html" ServerName domain.ru ServerAlias www.domain.ru ServerAlias external.domain.ru <Directory "/home/domain/public_html"> Allow from all Options -Indexes </Directory> <IfModule mpm_itk_module> AssignUserId domain sites </IfModule> ErrorLog /home/domain/logs/domain-error.log LogLevel warn CustomLog /home/domain/logs/domain-access.log combined </VirtualHost> 

    So, let's start to disassemble ...

    1. DocumentRoot - the main directory of the site
    2. ServerName - the domain that will be mapped to directories
    3. ServerAlias - a mirror of the name of item 2
    4. Starting with <Directory , the configuration of the directory itself goes. Here important - Options -Indexes - ban listing directory
    5. Now the most delicious mpm_itk_module is the launch of scripts, and indeed the execution in this host will come from the user registered in AssignUserId . Very convenient, if several sites. Having gained control, it is necessary for one site to fail to do something with another). For each site there must be a separate user. Also the specified module must be installed, here is the instruction . If it is not configured, there will be no error.
    6. ErrorLog , LogLevel and CustomLog - apache logging for this host. You can choose its parameters yourself)

    Everything is quite simple. If there are difficulties, write, we will understand, we will help!

    PS: I highly recommend putting mod_security on the server, otherwise you can pay well)

      You need the registrar's DNS servers (if you use them) to send your real ip-address to requests to site.com and site.ru. Next, you need to make the appropriate changes to the apache2 config. Here is a link to apache2 vHost , to the apache2 documentation (namely, to the section dedicated to virtual hosts), everything is described very clearly. There will be questions - write.