Apache-2.4

您無權訪問何時在 apache 中的單個 IP 地址上設置兩個基於名稱的網站

  • September 7, 2018

Apache 安裝在我的 debian 上,我想將兩個域名綁定到不同的目錄。

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

兩個域名都綁定了127.0.0.1。

貓 /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>

創建文件 .

touch  /var/log/apache2/error_hwy.log
touch  /var/log/apache2/access_hwy.log
touch  /var/log/apache2/error_app.log
touch  /var/log/apache2/access_app.log
sudo chown -R www-data:www-data /home/debian9/app
sudo chmod -R g+rw /home/debian9/app
sudo systemctl restart  apache2

test.html/var/www/html和中保存相同的文件/home/debian9/app

<p>it is a test</p>

為什麼www.hwy.local/test.html可以打開,www.test.app 出錯。

`This site can’t be reached` 

curl -i  www.test.app/test.html
HTTP/1.1 403 Forbidden
Date: Fri, 07 Sep 2018 09:08:13 GMT
Server: Apache/2.4.25 (Debian)
Content-Length: 296
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /test.html
on this server.<br />
</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at www.test.app Port 80</address>
</body></html>

不能設置DocumentRootfor www.test.appas /home/debian9/app which is different from /var/www/htmlforwww.hyw.local嗎?

allow from all

是 Apache 2.2 的配置語法。對於 Apache 2.4,這應該是

Require all granted

引用自:https://serverfault.com/questions/929883