Welcome! Log In Create A New Profile

Advanced

Nagios on nginx with fcgi/fcgiwrap

Posted by hburnswell 
Nagios on nginx with fcgi/fcgiwrap
September 07, 2017 08:23AM
Hi All,

I am trying to set up Nagios to run with nginx using fcgi/fcgiwrap and am receiving a "connection refused" to the defined socket:

2017/09/06 17:32:12 [error] 117059#117059: *5 connect() to unix:/var/run/fcgiwrap.socket failed (111: Connection refused) while connecting to upstream, client: 10.29.14.22, server: nagios.node.com, request: "GET /nagios/cgi-bin/status.cgi?hostgroup=all&style=hostdetail HTTP/1.1", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "server.node.com:8000", referrer: "http://server.node.com:8000/side.php"

rhel 7
nginx 1.12.1
php 5.4.16
php-fpm 5.4.16
fcgi-2.4.0-25.el7.x86_64
fcgiwrap-1.1.0-1.gf.el7.x86_64

I've been trouble-shooting for a couple days now and have found some info searching around but haven't found a solution yet. I am a novice when it comes to php/fcgi*.

I have read that I can use systemd for fcgiwrap and am attempting to use the following for the service:

fcgiwrap.service -

[Unit]
Description=Simple CGI Server
After=nss-user-lookup.target

[Service]
ExecStart=/usr/sbin/fcgiwrap
User=nginx
Group=nginx

[Install]
Also=fcgiwrap.socket

fcgiwrap.socket -

[Unit]
Description=fcgiwrap Socket

[Socket]
SocketMode=0600
SocketUser=nginx
SocketGroup=nginx
ListenStream=/var/run/fcgiwrap.socket

[Install]
WantedBy=sockets.target

When I start the service:

# systemctl start fcgiwrap.service
# systemctl status fcgiwrap.service

fcgiwrap.service - Simple CGI Server
Loaded: loaded (/etc/systemd/system/fcgiwrap.service; indirect; vendor preset: disabled)
Active: inactive (dead)

Sep 06 16:31:33 server systemd[1]: Started Simple CGI Server.
Sep 06 16:31:33 server systemd[1]: Starting Simple CGI Server...
Sep 06 17:01:00 server systemd[1]: Started Simple CGI Server.
Sep 06 17:01:00 server systemd[1]: Starting Simple CGI Server...
Sep 06 17:08:01 server systemd[1]: Started Simple CGI Server.
Sep 06 17:08:01 server systemd[1]: Starting Simple CGI Server...
Sep 06 17:20:55 server systemd[1]: Started Simple CGI Server.
Sep 06 17:20:55 server systemd[1]: Starting Simple CGI Server...
Sep 06 17:28:16 server systemd[1]: Started Simple CGI Server.
Sep 06 17:28:16 server systemd[1]: Starting Simple CGI Server...

Here are my config files:

nginx.conf -

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log debug;
pid /var/run/nginx.pid;


events {

worker_connections 1024;

}


http {

include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;

}

nagios.conf -

server {

listen 8000;
server_name nagios.node.com;

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

root /usr/local/nagios/share;
index index.php index.html;

auth_basic "Protected Site";
auth_basic_user_file .nagios;

location /stylesheets {

alias /usr/local/nagios/share/stylesheets;

}

location ~ .cgi$ {

root /usr/local/nagios/sbin/;
include fastcgi_params;
rewrite ^/nagios/cgi-bin/(.*).cgi /$1.cgi break;
fastcgi_param AUTH_USER $remote_user;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;

}

location ~ .php$ {

include fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm/nagios.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/share$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;

}

location ~ (.*.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf))$ {

root /usr/local/nagios/share/;
rewrite ^/nagios/(.*) /$1 break;
access_log off; expires max;

}

}

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 REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;

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;

fcgiwrap.socket -

ll /var/run/fcgiwrap.socket
-rw-rw---- 1 nginx nginx 0 Sep 6 17:27 /var/run/fcgiwrap.socket

php-fpm.d www.conf -

[www]

listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1

user = nginx
group = nginx

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

slowlog = /var/log/php-fpm/www-slow.log

php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session

php-fpm.d nagios.conf -

[nagios]

;listen 127.0.0.1:9000
listen = /var/run/php-fpm/nagios.socket
listen.owner = nginx
listen.group = nginx
listen.mode=0660
listen.allowed_clients = 127.0.0.1

user = nagios
group = nagios

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

slowlog = /var/log/php-fpm/www-slow.log

php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/php-fpm/nagios-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session


As mentioned, I am very much a novice when it comes to php and fcgi. But it appears that the socket is not in a listening mode since a status check returns:

Active: inactive (dead)

Any guidance would be greatly appreciated, thanks in advance.

P.S. - I did not know how to format with blockquotes, etc so I apologize for running everything together..

HB
Re: Nagios on nginx with fcgi/fcgiwrap
September 08, 2017 02:00PM
All,

I wanted to update status..

I have been working on this and learned a lot more on fastcgi in general. This link provided great information:

https://www.digitalocean.com/community/tutorials/understanding-and-implementing-fastcgi-proxying-in-nginx

I believe I have everything working fine with php-fpm. I (obviously) was confused with needing both php-fpm AND fcgiwrap.

My problem is my PATH_INFO variable, and I am working to figure out why.

It is unfortunate that this board isn't more active as there doesn't appear to be any other forums for nginx. I guess it is what it is...

HB
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 242
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready