A
A
Alexander2017-02-13 10:02:01
Apache HTTP Server
Alexander, 2017-02-13 10:02:01

Problem with virtual hosts for subdomains in Apache?

The directory structure is as follows:
/var/www/test.ru
/var/www/test.ru/httpd
/var/www/test.ru/forum
/var/www/test.ru/media
The site itself is located in the "httpd" folder domain, and in the "forum" folder, respectively, the subdomain "forum.test.ru" itself.
hosts file:

127.0.0.1       localhost
127.0.1.1       WS01
127.0.0.1       test.ru
127.0.0.1       forum.test.ru
127.0.0.1       media.test.ru

Well, the file /etc/apache2/sites-available/test.ru.conf
<VirtualHost *:80>

        ServerAdmin [email protected]
        DocumentRoot /var/www/test.ru/httpd
        ServerName test.ru
        ServerAlias www.test.ru

        <Directory /var/www/test.ru/httpd>
           Options Indexes FollowSymlinks
           AllowOverride All
           Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

<VirtualHost *:80>

        ServerAdmin [email protected]
        DocumentRoot /var/www/test.ru/forum
        ServerName forum.test.ru
        ServerAlias www.forum.test.ru

        <Directory /var/www/test.ru/forum>
           Options Indexes FollowSymlinks
           AllowOverride All
           Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
<VirtualHost *:80>

        ServerAdmin [email protected]
        DocumentRoot /var/www/test.ru/media
        ServerName media.test.ru
        ServerAlias www.media.test.ru

        <Directory /var/www/test.ru/media>
           Options Indexes FollowSymlinks
           AllowOverride All
           Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

When you try to add another section for "media" and add 127.0.0.1 with the "media.test.ru" parameter to the hosts file, Apache swears that he does not like VirtualHost. Tell me where I messed up?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2017-02-13
@shambler81

<VirtualHost 127.0.0.1:80>
        ServerName  test.ru
        ServerAlias www.test.ru
        ServerAdmin [email protected]
        DocumentRoot  /var/www/test.ru/httpd
        ErrorLog logs/test_ru_error_log
        LogLevel warn
        CustomLog logs/test_ru_assest_log combined

       <Directory /var/www/test.ru/httpd>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                DirectoryIndex index.php index.html index.htm
                Order allow,deny
                allow from all
       </Directory>
</VirtualHost>


<VirtualHost 127.0.0.1:80>
        ServerName  forum.test.ru
        ServerAlias www.forum.test.ru
        ServerAdmin [email protected]
        DocumentRoot  /var/www/forum.test.ru/httpd
        ErrorLog logs/forum_test_ru_error_log
        LogLevel warn
        CustomLog logs/forum_test_ru_assest_log combined

       <Directory /var/www/forum.test.ru/httpd>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                DirectoryIndex index.php index.html index.htm
                Order allow,deny
                allow from all
       </Directory>
</VirtualHost>

<VirtualHost 127.0.0.1:80>
        ServerName  media.test.ru
        ServerAlias www.media.test.ru
        ServerAdmin [email protected]
        DocumentRoot  /var/www/media.test.ru/httpd
        ErrorLog logs/media_test_ru_error_log
        LogLevel warn
        CustomLog logs/media_test_ru_assest_log combined

       <Directory /var/www/media.test.ru/httpd>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                DirectoryIndex index.php index.html index.htm
                Order allow,deny
                allow from all
       </Directory>
</VirtualHost>

B
Boris Korobkov, 2017-10-04
@BorisKorobkov

  1. In the form of possible injection
    Etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question