-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 
2
  • 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 7, 2018 at 9: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 7, 2018 at 10:49

1 Answer 1

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.

3
  • issure remains here.
    – scrapy
    Sep 7, 2018 at 9:09
  • You don't have permission to access /test.html
    – scrapy
    Sep 7, 2018 at 9: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 7, 2018 at 10:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .