I am trying to setup Nagios on my server which is set up to run NGINX and PHP-FPM.
The nginx-config
file for my site is:
server {
listen 80;
listen [::]:80;
root /var/www/nagios;
index index.html index.htm index.php;
auth_basic "Nagios Restricted Access";
auth_basic_user_file /usr/local/nagios/etc/htpasswd.users ;
server_name <hidden for stackoverflow>;
location / {
root /var/www/nagios/html;
try_files $uri $uri/ =404;
}
location ~ \.cgi$ {
gzip off;
root /var/www/nagios/cgi;
include fastcgi_params;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param AUTH_USER $remote_user;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
location ~ \.php$ {
root /var/www/nagios/html;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Nagios is installed at /var/www/nagios/
.
The PHP-files and html are located at /var/www/nagios/html
.
The CGI files are located at /var/www/nagios/cgi/
However, when I try to run Nagios, I get 403 forbidden on all .cgi
file pages.
And when I try service fcgiwrap status
I get the following error:
Cannot get script name, are DOCUMENT_ROOT and SCRIPT_NAME (or SCRIPT_FILENAME) set and is the script executable?
There are no errors thrown in the nginx error.log
All files in /var/www/nagios/cgi
are executable, and owned by www-data:www-data
as they are in /var/www/nagios/html
.
I have no clue where to go from here. Any tips?
UPDATE:
I found out that all of the CGI files are linked like this: http://example.com/nagios/cgi-bin/status.cgi
When I access these I get to 403 Forbidden error, but if I go to http://example.com/status.cgi, it works.
So I guess my new question is: How can I change my rewrite rule so that nagios/cgi-bin/status.cgi
is rewritten to local path of /var/www/nagios/cgi/status.cgi
?
I guess, $fastcgi_script_name
passes along the entire path of nagios/cgi-bin/status.cgi
right now.