以下是Debian LAMP中Apache的配置指南:
更新系統包列表:sudo apt update
,然后安裝Apache:sudo apt install apache2
,安裝后Apache會自動啟動。
Apache主配置文件位于/etc/apache2/
目錄下,主要有apache2.conf
、ports.conf
等??稍?code>apache2.conf中設置服務器信息、監聽端口等;在ports.conf
中定義Apache監聽的端口。
在/etc/apache2/sites-available/
目錄下創建虛擬主機配置文件,如example.com.conf
,添加如下內容:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
然后啟用虛擬主機:sudo a2ensite example.com.conf
,并重啟Apache:sudo systemctl restart apache2
。
可通過設置ServerTokens Prod
和ServerSignature Off
隱藏服務器信息。使用<Directory>
指令限制目錄訪問權限,防止目錄遍歷攻擊。還可啟用SSL/TLS加密,配置防火墻限制訪問等。