-2

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 
scrapy
  • 337
  • 4
  • 17
  • Look into `/var/log/apache2/error_app.log` and `/var/log/apache2/access_app.log`. Also add the output of `namei -olm /home/debian9/app/index.html`. – Thomas Sep 07 '18 at 09:55
  • 1
    The permissions problem is because you've configured the second vhost to keep its files in a subdirectory under `/home` instead of under `/var/www/html`. Do a search for "apache directory permissions" on this site, and you'll find lots of similar questions that will help you. – Jenny D Sep 07 '18 at 10:49

1 Answers1

3

The problem isn't with Apache, it's with your /etc/hosts file.

You can only have one line in the hosts file per IP address. So your hosts file should look like this:

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

with all the entries for 127.0.0.1 on one and the same line.

Jenny D
  • 27,780
  • 21
  • 75
  • 114
  • issure remains here. – scrapy Sep 07 '18 at 09:09
  • You don't have permission to access /test.html – scrapy Sep 07 '18 at 09:09
  • 1
    When I answered, the issue you had was `Site can't be reached` and thaẗ́s what I answered. We generally prefer that people don't change the questions when they encounter a new problem, because it'll make the answer a lot less useful for other readers in the future. – Jenny D Sep 07 '18 at 10:47