Nagios 的 Nginx 别名不起作用

Nagios 的 Nginx 别名不起作用

我正在将一台服务器设置为 Nagios 监控服务器,但遇到了一个问题。

如果我访问 URL nagios.myserver.com/nagios/ (或 nagios.myserver.com/nagios/index.php),服务器会尝试重定向到 /opt/nagios/share/s/index.php

正确的文件夹是:/opt/nagios/share/

我不知道 /s/ 是从哪里来的。

错误日志:

2011/11/06 00:16:28 [error] 1818#0: *13 open() "/opt/nagios/share/s/index.php" failed (2: No such file or directory), client: 75.xxxxxxxxxxxxxx, server: nagios.myserver.com, request: "GET /nagios/ HTTP/1.1", host: "nagios.myserver.com"

我的 /etc/nginx/sites-enabled/nagios.myserver.com.conf 文件:

    server {
        server_name nagios.myserver.com;

        access_log  /var/log/nginx/nagios.myserver.com.access.log;
        error_log   /var/log/nginx/nagios.myserver.com.error.log;

  auth_basic            "Restricted Nagios Area!";
  auth_basic_user_file  /opt/nagios/etc/htpasswd.users;

        root    /var/www/nagios.myserver.com;
        index   index.php index.html;

   location / {
    try_files $uri $uri/ index.php;
    auth_basic            "Restricted";
    auth_basic_user_file  /opt/nagios/etc/htpasswd.users;
  }

  location /nagios {
    alias /opt/nagios/share/;
  }

  location ~ ^/nagios/(.*\.php)$ {
    alias /opt/nagios/share/$1;
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
  }

  location ~ \.cgi$ {
    root /opt/nagios/sbin/;
    rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
    fastcgi_param AUTH_USER $remote_user;
    fastcgi_param REMOTE_USER $remote_user;
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
  }

  location ~ \.php$ {
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
  }
}

fastcgi.conf的内容:

location ~ \.php$ {
    include /etc/nginx/fastcgi_params;

    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    if (-f $request_filename) {
        fastcgi_pass unix:/var/run/www/php.sock;
    }
}

fastcgi_参数:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

调试:

2011/11/06 01:30:29 [debug] 5226#0: *1 open index "/opt/nagios/share/index.php"
2011/11/06 01:30:29 [debug] 5226#0: *1 internal redirect: "/nagios/index.php?"
2011/11/06 01:30:29 [debug] 5226#0: *1 generic phase: 1
2011/11/06 01:30:29 [debug] 5226#0: *1 test location: "/"
2011/11/06 01:30:29 [debug] 5226#0: *1 test location: "nagios"
2011/11/06 01:30:29 [debug] 5226#0: *1 test location: ~ "^/nagios/(.*\.php)$"
2011/11/06 01:30:29 [debug] 5226#0: *1 test location: ~ "\.php$"
2011/11/06 01:30:29 [debug] 5226#0: *1 using configuration "\.php$"
2011/11/06 01:30:29 [debug] 5226#0: *1 http cl:-1 max:1048576
2011/11/06 01:30:29 [debug] 5226#0: *1 generic phase: 3
2011/11/06 01:30:29 [debug] 5226#0: *1 http script complex value
2011/11/06 01:30:29 [debug] 5226#0: *1 http script copy: "/opt/nagios/share/"
2011/11/06 01:30:29 [debug] 5226#0: *1 http script capture: ""
2011/11/06 01:30:29 [debug] 5226#0: *1 http script copy: "/opt/nagios/share/"
2011/11/06 01:30:29 [debug] 5226#0: *1 http script capture: ""
2011/11/06 01:30:29 [debug] 5226#0: *1 http script var: "/opt/nagios/share/s/index.php"
2011/11/06 01:30:29 [debug] 5226#0: *1 http script copy: ""
2011/11/06 01:30:29 [debug] 5226#0: *1 http script file op 00000000 "/opt/nagios/share/s/index.php"
2011/11/06 01:30:29 [debug] 5226#0: *1 http script file op false
2011/11/06 01:30:29 [debug] 5226#0: *1 http script if
2011/11/06 01:30:29 [debug] 5226#0: *1 http script if: false
2011/11/06 01:30:29 [debug] 5226#0: *1 post rewrite phase: 4
2011/11/06 01:30:29 [debug] 5226#0: *1 generic phase: 5
2011/11/06 01:30:29 [debug] 5226#0: *1 generic phase: 6
2011/11/06 01:30:29 [debug] 5226#0: *1 generic phase: 7
2011/11/06 01:30:29 [debug] 5226#0: *1 access phase: 8
2011/11/06 01:30:29 [debug] 5226#0: *1 access phase: 9

我保留了一些调试,因为我认为这部分应该会有所帮助,尽管我仍然无法弄清楚。

有任何想法吗?

我对 NginX 还很陌生。

谢谢。

答案1

听起来您的配置中某处有一个重写规则。它是什么fastcgi.conf样子的?

您可以使用以下方式进行快速搜索:

# grep -lr rewrite /etc/nginx/
# grep -lr include /etc/nginx/

尝试将 更改location /nagios为 ,location /abc看看它是否重定向到/opt/nagios/share/c/index.php。如果没有,我建议您打开调试并查看错误日志。

相关内容