要自定義Ubuntu Apache2的錯誤頁面,請按照以下步驟操作:
sudo apt update
sudo apt install apache2
/var/www/html
目錄下創建一個名為custom-error-pages
的目錄:sudo mkdir /var/www/html/custom-error-pages
sudo chmod 644 /var/www/html/custom-error-pages/404.html
/etc/apache2/apache2.conf
或/etc/apache2/sites-available/000-default.conf
。使用文本編輯器打開它,例如nano:sudo nano /etc/apache2/apache2.conf
或者
sudo nano /etc/apache2/sites-available/000-default.conf
<VirtualHost>
標簽內添加以下代碼,以指定自定義錯誤頁面的位置:ErrorDocument 404 /custom-error-pages/404.html
將404
替換為要自定義的錯誤代碼,將/custom-error-pages/404.html
替換為實際的文件路徑。
保存并關閉配置文件。
重新啟動Apache2服務以使更改生效:
sudo systemctl restart apache2
現在,當用戶訪問不存在的頁面時,Apache2將顯示您自定義的錯誤頁面。您可以按照相同的方法為其他錯誤代碼(如403、500等)創建自定義錯誤頁面。