Linux 支援廣泛硬體平台,CPU 方面:
硬體相容性查詢:訪問 Linux 官網硬體相容性清單 (HCL) 確認具體型號支援狀況。記憶體、磁碟、網卡等元件主流廠牌均有良好驅動支援。
Linux 平台主流 Web 伺服器:
版本對應:
| 發行版 | 內建 Apache 版本 | 配置根目錄 | 文檔根目錄 | 啟動腳本目錄 |
|---|---|---|---|---|
| Red Hat 5.2 | 1.3.x | /etc/httpd | /home/httpd/html | /etc/rc.d/ |
| Slackware | 1.3.x | /etc/httpd | /var/www/htdocs | /etc/rc.d/ |
| OpenLinux | 1.3.x | /etc/httpd | /usr/local/httpd/htdocs | /etc/rc.d/ |
# rpm -ivh apache-1.3.x-i386.rpm
安裝完成後,啟動 X Window 瀏覽器訪問 https://本機IP/,出現 "It worked!" 頁面即表示二進制安裝成功,可進入配置階段。
# tar -xzvf apache_1.3.x.tar.gz
# cd apache_1.3.x
# ./configure --prefix=/usr/local/apache --enable-module=so --enable-rule=SHARED_CORE
# make && make install
--enable-module=so 啟用 DSO 動態模組載入支援,強烈建議開啟。
httpd.conf (核心引擎)
↓ Include/讀取
srm.conf (資源映射)
↓ Include/讀取
access.conf (存取控制)
啟動順序:httpd.conf → srm.conf → access.conf。副本備份同目錄下保留 .default 後綴檔案。
| 指令 | 功能 | 範例/預設 | 說明 |
|---|---|---|---|
ServerRoot | 伺服器安裝根目錄 | /etc/httpd | 所有相對路徑基準;含 conf/, logs/, modules/ 子目錄 |
Port | 監聽埠號 | 80 | Standalone 模式綁定;inetd 模式忽略此設定 |
User / Group | 運行身份降權帳號 | www / www | 安全原則:嚴禁以 root 運行子進程;帳號需預先建立 |
ServerAdmin | 管理員聯絡郵箱 | webmaster@example.com | 錯誤頁面顯示,便於用戶回報問題 |
ErrorLog | 錯誤日誌路徑 | logs/error_log | 相對路徑基於 ServerRoot;建議獨立分區存儲 |
TransferLog | 存取日誌路徑 | logs/access_log | Common Log Format (CLF);支援 LogFormat 自定義格式 |
VirtualHost | 虛擬主機容器 | - | 單 IP 多域名 (Name-based) 或多 IP 多站點 (IP-based) 核心配置 |
LoadModule | 動態載入模組 | LoadModule php4_module libexec/libphp4.so | DSO 機制核心;模組檔案位於 ServerRoot/modules/ 或 libexec/ |
AddModule | 靜態編譯模組啟用順序 | AddModule mod_php4.c | Apache 1.3 僅靜態模組需此指令;DSO 模組無需 |
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /home/httpd/html/example
ServerAdmin webmaster@example.com
ErrorLog logs/example-error_log
TransferLog logs/example-access_log
</VirtualHost>
<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /home/httpd/html/blog
ServerAdmin blog@example.com
</VirtualHost>
關鍵點:NameVirtualHost 必須啟用;ServerName 必須與 DNS A 記錄一致;DocumentRoot 目錄需預先建立並設正確權限。
# /usr/sbin/httpd -t ; 語法檢查 (僅驗證不啟動)
# /usr/sbin/apachectl graceful ; 平滑重啟 (不中斷現有連線)
# /usr/sbin/apachectl restart ; 完全重啟