Ubuntu 20.04 常用指令集
系統設置篇
(1)更改系統名稱
sudo hostnamectl set-hostname host.example.com
(2)更改靜態IP設置
sudo nano /etc/netplan/00-installer-config.yaml
設置IP後使其生效
sudo netplan apply
Apache篇
(1)啟用 AllowOverride
.htaccess 在 Apache 中默認會被忽略。如果這是你會使用到的東西,我們可以通過更改 Apache 配置文件來啟用它。
首先,備份配置文件。
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
打開配置文件。
sudo nano /etc/apache2/apache2.conf
按 CTRL + W 並蒐索 <Directory /var/www/>。或者,向下滾動到以下部分:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AllowOverride None 代表 .htaccess 會被忽略。將它更改為 AllowOverride All。
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
保存並退出(按 CTRL + X,按 Y,然後按 ENTER)。
重啟 Apache。
sudo systemctl reload apache2
(2)啟用 mod_rewrite
如果想在 .htaccess 中配置一些規則,會需要啟用 mod_rewrite。
sudo a2enmod rewrite
重啟 Apache。
sudo systemctl reload apache2
(3)禁用目錄列表(Disable Directory Listing)
預設情況下,Apache 將列出沒有索引(index.html、index.php)的目錄內容。這會有安全風險,因為它可能允許駭客任意瀏覽你的網頁伺服器。
您可以通過從 Apache 配置文件中刪除索引(下面的紅色部分)來禁用此功能。
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
保存並退出(按 CTRL + X,按 Y,然後按 ENTER)。
重啟 Apache。
sudo systemctl reload apache2