我最近安裝了 ubuntu 22.04 并嘗試在其上使用 LAMP。但我對 VirtualHost 有疑問。我想使用帶有本地域的虛擬主機,例如:test.local 我將此域添加到 /etc/hosts 并將此配置添加到我的 test.local.conf:
<VirtualHost *:80>
ServerName test.local
ServerAdmin webmaster@localhost
DocumentRoot /home/soroush/Sites/test
<Directory "/home/soroush/Sites/test" >
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
然后運行:a2ensite test.local.conf 但是當我在瀏覽器中打開 test.local 時,apache 顯示 403 錯誤。站點/測驗檔案夾和檔案具有 0777 權限,所有者是我的用戶名。我應該怎么做才能解決這個問題?
uj5u.com熱心網友回復:
我的解決方案是降級到 20.04 ;) 對不起,如果我不能給你一個更好的解決方案。
uj5u.com熱心網友回復:
默認情況下,Ubuntu 不允許通過 Web 瀏覽器訪問除位于 /var/www、public_html 目錄(啟用時)和 /usr/share(用于 Web 應用程式)中的檔案之外的任何檔案。如果您的站點使用位于其他位置(例如 /srv)的 Web 檔案根目錄,您可能需要在 /etc/apache2/apache2.conf 中將您的檔案根目錄列入白名單。默認的 Ubuntu 檔案根目錄是 /var/www/html。您可以在 /var/www 下創建自己的虛擬主機。
這與以前的版本不同,它提供了更好的開箱即用安全性。
解決問題:
將源代碼移動到 /var/www
示例:/var/www/site
2.修復你的虛擬主機
<VirtualHost *:80>
ServerName test.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/site
<Directory "/var/www/site" >
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/472125.html
上一篇:終端集中程式的輸出到字串?
