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

Nagios 安裝後左側選單無反應?CGI 路徑配置錯誤快速修復

編輯:Linux 教學

問題現象

Nagios 安裝啟動成功,但 Web 介面左側選單點擊無反應、CGI 頁面 404,核心原因是 CGI 執行檔路徑與 Apache 配置不匹配。

根本原因

  • Nagios 編譯安裝預設將 CGI 放在 /usr/local/nagios/sbin/。
  • Apache ScriptAlias /nagios/cgi-bin/ 指向 /usr/local/apache/cgi-bin/(或 /var/www/cgi-bin/)。
  • Web 介面設定檔 /usr/local/nagios/share/config.inc.php 中 $cfg["cgi_base_url"] 指向錯誤路徑。

快速修復方案(三選一)

方案 A:複製 CGI 到 Apache 指定目錄(最快生效)

# 1. 複製所有 CGI 執行檔
cp /usr/local/nagios/sbin/*.cgi /usr/local/apache/cgi-bin/

# 2. 確認 Apache 配置包含 ScriptAlias
# /etc/httpd/conf/httpd.conf 或 /etc/apache2/conf-available/nagios.conf
ScriptAlias /nagios/cgi-bin/ /usr/local/apache/cgi-bin/

# 3. 重啟 Apache
systemctl restart httpd  # 或 apache2

方案 B:修改 Nagios Web 設定指向實際 CGI 目錄(推薦,避免重複檔案)

# 編輯設定檔
vi /usr/local/nagios/share/config.inc.php

# 修改 cgi_base_url 指向實際 sbin 目錄(需 Apache 允許執行)
$cfg["cgi_base_url"] = "/nagios/cgi-bin";  # 若 Apache ScriptAlias 指向 sbin
# 或
$cfg["cgi_base_url"] = "/nagios/sbin";     # 若直接 Alias 到 sbin

# 同步修改 Apache 配置
Alias /nagios/sbin/ /usr/local/nagios/sbin/
<Directory /usr/local/nagios/sbin>
    Options ExecCGI
    AllowOverride None
    Require all granted
</Directory>

方案 C:重新編譯安裝指定 CGI 目錄(源頭解決)

./configure --with-cgi-url=/nagios/cgi-bin --with-httpd-conf=/etc/httpd/conf.d
make all && make install && make install-webconf

驗證步驟

  1. 瀏覽器訪問 https://IP/nagios/。
  2. 點擊左側「Service Detail」、「Host Detail」等連結,應正常顯示 CGI 頁面(URL 含 /cgi-bin/)。
  3. 若仍 404,檢查 Apache 錯誤日誌 /var/log/httpd/error_log 確認權限或路徑問題。

權限關鍵點

  • CGI 檔案擁有者通常為 nagios:nagios,Apache 運行用戶(apache/www-data)需有執行權限。
  • 目錄需 Options +ExecCGI,檔案需 chmod 755。
  • SELinux 環境需設定 setsebool -P httpd_enable_cgi 1 或調整標籤。

結語

Nagios CGI 路徑不匹配是經典安裝坑。方案 B(修改配置指向實際目錄)最乾淨,避免檔案重複與升級同步問題。記得同步調整 Apache Alias/ScriptAlias 與目錄權限。

Copyright © Windows教程網 All Rights Reserved