Nagios的Nginx别名不能正常工作

我正在build立一个服务器作为一个Nagios监控服务器,我遇到了一个问题。

如果我转到urlnagios.myserver.com/nagios/(或nagios.myserver.com/nagios/index.php),则服务器尝试redirect到/opt/nagios/share/s/index.php

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

我不知道这是从哪里来的。

错误日志:

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_params:

 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; 

debugging:

 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 

我保留了一些debugging,因为我认为这部分应该帮助,但我仍然无法弄清楚。

有任何想法吗?

我对NginX来说很新。

谢谢。

这听起来像是在你的configuration中有一个重写规则。 fastcgi.conf什么样的?

您可以使用以下方法快速search:

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

尝试将location /nagios更改为location /abc以查看它是否redirect到/opt/nagios/share/c/index.php 。 如果没有,我build议你打开debugging,看看错误日志。