Почему я не могу установить два виртуальных хоста в моем apache?

Apache was installed on my debian,i want to bind two domain name with different directroy.

cat  /etc/hosts
127.0.0.1  hwy.local  www.hwy.local  
127.0.0.1  test.app   www.test.app

Two domain name all binded with 127.0.0.1.

cat /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
    ServerName www.hwy.local
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error_hwy.log
    CustomLog ${APACHE_LOG_DIR}/access_hwy.log combined
        <Directory /var/www/html>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
        </Directory>
</VirtualHost>
<VirtualHost *:80>

ServerName www.test.app
ServerAdmin webmaster@localhost
DocumentRoot  /home/debian9/app
ErrorLog ${APACHE_LOG_DIR}/error_app.log
CustomLog ${APACHE_LOG_DIR}/access_app.log combined
    <Directory /home/debian9/app>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

Save the same file test.html in both /var/www/html and /home/debian9/app.

<p>it is a test</p>

Why www.hwy.local/test.html can open it ,www.test.app run into error.

This site can’t be reached 
-2
задан 7 September 2018 в 14:25
1 ответ

Проблема не в Apache,это с вашим файлом / etc / hosts .

Вы можете иметь только одну строку в файле hosts на каждый IP-адрес. Итак, ваш файл hosts должен выглядеть так:

127.0.0.1  hwy.local  www.hwy.local  test.app   www.test.app

со всеми записями для 127.0.0.1 в одной и той же строке.

3
ответ дан 5 December 2019 в 21:10

Теги

Похожие вопросы