Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Linux 平台 Apache Web 伺服器架設完整指南:安裝、配置與安全基礎

編輯:關於伺服器

Linux Web 伺服器方案選型

Linux 系統常見 Web 伺服器:CERN、NCSA、Apache 三種。Apache 以跨平台、配置簡明、最大兼容性成為首選。特色功能:整合代理伺服器、Perl 腳本、會話追蹤、日誌定製、虛擬主機、HTTP 認證等。配合 Linux 強大內核,構建高性能 Web 平台。

Apache 安裝途徑

方式一:預編譯二進制包(適合初學者)

# 下載範例:apache_1.3.x.tar.gz
tar xvzf apache_1.3.x.tar.gz
# 解壓即完成安裝

方式二:原始碼編譯安裝(RPM 包)

# 安裝 RPM
rpm -ivh apache_1.3.x.rpm

# 進入源碼目錄配置編譯
cd /usr/src/apache-1.3.x
./configure
make

# 複製執行檔與配置檔
cp httpd /etc/httpd/bin/
cp httpd.conf access.conf srm.conf mime.types /etc/httpd/conf/

大多數 Linux 發行版預裝 Apache,若未安裝可從安裝光碟或 Apache 官網 獲取(提供源碼與二進制包兩種版本)。

Apache 核心配置檔案詳解

啟動 Web 服務僅需將 Linux 接入互聯網,主頁放置於 /home/httpd。為提升效能需深度配置四大核心檔案:

1. httpd.conf - 主配置檔(伺服器運行環境)

指令說明範例
ServerType運行模式:standalone(獨立守護進程,高效能,預設)
inetd(較安全,RedHat 預設)
ServerType standalone
Port主進程監聽埠Port 80
ErrorLog錯誤日誌路徑ErrorLog /var/httpd/error.log
ServerRoot配置與日誌儲存根目錄ServerRoot /etc/httpd
ServerAdmin管理員郵箱ServerAdmin admin@example.com

inetd 模式額外配置:

# /etc/inetd.conf 新增:
httpd stream tcp nowait httpd /etc/httpd/bin/httpd -f /etc/httpd/conf/httpd.conf

# /etc/services 新增:
httpd 80/tcp httpd

2. srm.conf - 資源配置檔(站點資源發布策略)

指令說明範例
DocumentRoot主文檔根目錄DocumentRoot /home/httpd/html
DirectoryIndex預設首頁檔名(支援多備選)DirectoryIndex index.html index.htm

啟動服務與驗證

# 重啟 Apache 使配置生效
/etc/rc.d/init.d/httpd restart

# 或使用系統服務腳本
service httpd restart

Apache 安全認證機制

基於主機地址的存取控制

透過 IP/網段允許/拒絕存取。但現今多數用戶使用動態 IP,實用性有限。

基於用戶名/密碼的認證(推薦)

適應動態 IP 環境,安全性更高。具體實現涉及 htpasswd 建立密碼檔、.htaccess 或 httpd.conf 定義保護領域、AuthType、AuthUserFile、Require valid-user 等指令。詳細配置超出本文範圍,請參閱 Apache 官方文檔進階學習。

遷移建議

生產環境建議:

  • 升級至 Apache 2.4+ 獲得效能與安全增強
  • 啟用 ModSecurity WAF 防護應用層攻擊
  • 配置 SSL/TLS 強制 HTTPS
  • 實施日誌審計與異常監控
  • 定期安全基線掃描與修補
Copyright © Windows教程網 All Rights Reserved