溫馨提示×

Debian LAMP中Apache配置指南

小樊
37
2025-09-11 01:03:18
欄目: 智能運維

以下是Debian LAMP中Apache的配置指南:

安裝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 ProdServerSignature Off隱藏服務器信息。使用<Directory>指令限制目錄訪問權限,防止目錄遍歷攻擊。還可啟用SSL/TLS加密,配置防火墻限制訪問等。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女