Page 1 of 1

The requested URL /nagios/nagios/cgi-bin/status.cgi was not

Posted: Wed Oct 25, 2017 2:37 am
by trinetra
Hi all ,

Recently i have installed nagios core v4.3.4 on a centos server ( Centos 6.9 , 5GB RAM , 3 core ). The installation works perfectly fine when i launch from the direct public ip (no errors).
But when i put it behind a separate nginx and launch it using the domain name , i am getting errors as per the screenshot below. Below are my httpd.conf for nagios...really not sure how to fix this.
seeking your advice. Thanks in advance.

#httpd conf for nagios

Code: Select all

[root@m246nagios etc]# grep -v "#" /etc/httpd/conf.d/nagios.conf 

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
   Options ExecCGI
   AllowOverride None
   <IfVersion >= 2.3>
      <RequireAll>
         Require all granted

         AuthName "Nagios Access"
         AuthType Basic
         AuthUserFile /usr/local/nagios/etc/htpasswd.users
         Require valid-user
      </RequireAll>
   </IfVersion>
   <IfVersion < 2.3>
      Order allow,deny
      Allow from all

      AuthName "Nagios Access"
      AuthType Basic
      AuthUserFile /usr/local/nagios/etc/htpasswd.users
      Require valid-user
   </IfVersion>
</Directory>

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
   Options None
   AllowOverride None
   <IfVersion >= 2.3>
      <RequireAll>
         Require all granted

         AuthName "Nagios Access"
         AuthType Basic
         AuthUserFile /usr/local/nagios/etc/htpasswd.users
         Require valid-user
      </RequireAll>
   </IfVersion>
   <IfVersion < 2.3>
      Order allow,deny
      Allow from all

      AuthName "Nagios Access"
      AuthType Basic
      AuthUserFile /usr/local/nagios/etc/htpasswd.users
      Require valid-user
   </IfVersion>
</Directory>


# nagios home dir

Code: Select all

/usr/local/nagios/etc
# location of status.cgi

Code: Select all

/usr/local/nagios/sbin/status.cgi

Re: The requested URL /nagios/nagios/cgi-bin/status.cgi was

Posted: Wed Oct 25, 2017 12:53 pm
by mcapra
I'd be interested in seeing your cgi.cfg. It's typically found here:

Code: Select all

/usr/local/nagios/etc/cgi.cfg
trinetra wrote:But when i put it behind a separate nginx and launch it using the domain name
Is there a particular reason you're doing this? Could we also see the nginx configuration? The gist of your problem is that something is appending an extra /nagios/ to your URLs when stuffing those pages into the iframe. It wouldn't surprise me if nginx was doing that.

Re: The requested URL /nagios/nagios/cgi-bin/status.cgi was

Posted: Wed Oct 25, 2017 1:16 pm
by dwasswa
Thanks @ mcapra ,

@ trinetra, did you try what we suggested?

Re: The requested URL /nagios/nagios/cgi-bin/status.cgi was

Posted: Wed Oct 25, 2017 10:24 pm
by trinetra
hi mcapra & dwasswa,

below is the config "/usr/local/nagios/etc/cgi.cfg"

Code: Select all

[root@m246nagios nagios]# grep -v "#" /usr/local/nagios/etc/cgi.cfg
main_config_file=/usr/local/nagios/etc/nagios.cfg
physical_html_path=/usr/local/nagios/share
url_html_path=/nagios
show_context_help=0
use_pending_states=1
use_authentication=1
use_ssl_authentication=0
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
default_statuswrl_layout=4
ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$
refresh_rate=90
result_limit=100
escape_html_tags=1
action_url_target=_blank
notes_url_target=_blank
lock_author_names=1
navbar_search_for_addresses=1
navbar_search_for_aliases=1
[root@m246nagios nagios]# 

# reason i put my servers behind nginx is to hide direct access to the servers and easier to manage a group of web interfacing servers behind nginx - following is my nginx config for nagios

Code: Select all

[root@m109-c64-nginx conf.d]# grep -v "#" nagios.xxx.xxx.conf 
server {
       listen         80;
       server_name    nagios.xxx.xxx;
       return         301 https://$server_name$request_uri;
}
server {
       listen 443;
       root html;

       server_name nagios.xxx.xxx;
       error_log /var/log/nginx/nagios-xxxxx-error.log warn;

        ssl                  on;
        ssl_certificate      /etc/nginx/ssl/xxxxxBundle.crt;
        ssl_certificate_key  /etc/nginx/ssl/xxxxx.key;
        ssl_session_timeout  5m;
        ssl_protocols    TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers   on;

       location / {
                proxy_pass http://10.0.0.246/nagios/;
                proxy_redirect     off;
                proxy_set_header   Host             $host;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_cache_key         backend$request_uri;
                proxy_cache_valid       200 301 302 20m;
                proxy_cache_valid       404 1m;
                proxy_cache_valid       any 15m;
                proxy_cache_use_stale   error timeout invalid_header updating;

                proxy_http_version 1.1;
                proxy_set_header Connection $http_connection;
                proxy_set_header Origin http://$host;
                proxy_set_header Upgrade $http_upgrade;

        }
}



Re: The requested URL /nagios/nagios/cgi-bin/status.cgi was

Posted: Thu Oct 26, 2017 9:46 am
by mcapra
This isn't strictly Nagios Core related, but I think your location is inconsistent with your proxy_pass for this particular use case. I think the current problem is that your proxy is forwarding specifically to http://10.0.0.246/nagios/ on that address, eg if you access my_proxy_host:8989 it actually sets the reference to http://10.0.0.246/nagios/ per the proxy_pass setting. So when the links in the left-hand frame say /nagios/cgi-bin/status.cgi for the href, in the context of your proxy their full URI resolves to http://10.0.0.246/nagios//nagios/cgi-bin/status.cgi

The lazy way to fix this would be to explicitly include the /nagios location in your nginx conf:

Code: Select all

location /nagios {
                proxy_pass http://10.0.0.246/nagios/;
                # same TLS/Proxy settings as /
        }
The more appropriate way might be through rewrites or proxying /nagios to http://10.0.0.246/nagios and accessing Nagios Core's GUI through my_proxy_host:443/nagios instead of my_proxy_host:443. For the latter, like so:

Code: Select all

       location /nagios {
                proxy_pass http://10.0.0.246/nagios;
                proxy_redirect     off;
                proxy_set_header   Host             $host;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_cache_key         backend$request_uri;
                proxy_cache_valid       200 301 302 20m;
                proxy_cache_valid       404 1m;
                proxy_cache_valid       any 15m;
                proxy_cache_use_stale   error timeout invalid_header updating;

                proxy_http_version 1.1;
                proxy_set_header Connection $http_connection;
                proxy_set_header Origin http://$host;
                proxy_set_header Upgrade $http_upgrade;

        }
TL;DR iframes are weird sometimes and your proxy's paths should match the destination's paths. Admittedly I wrote that all up pretty quick and without a ton of spot checking, so if something doesn't make sense or sounds totally crazy let me know.

Re: The requested URL /nagios/nagios/cgi-bin/status.cgi was

Posted: Thu Oct 26, 2017 12:04 pm
by dwasswa
Thanks @mcapra ,@trinetra, please try what was suggested and give us an update if it solved your issue.

Also,please let us know if you have any questions.

Re: The requested URL /nagios/nagios/cgi-bin/status.cgi was

Posted: Thu Oct 26, 2017 10:09 pm
by trinetra
hi macpra,

yes, i have fix this now with the nginx config as mentioned by you .. thank you so much and also thanks to @dwasswa...
kindly close this thread as solved ( i don't see anywhere in the forum to 'mark as solved' ). thanks so much again @macpra @dwasswa :)
have a nice day !!


Code: Select all

location /nagios {
		#include /etc/nginx/auth/auth.conf;
                proxy_pass http://10.0.0.246/nagios/;
		#proxy_pass http://10.0.0.246/;
                proxy_redirect     off;
                proxy_set_header   Host             $host;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_cache_key         backend$request_uri;
                proxy_cache_valid       200 301 302 20m;
                proxy_cache_valid       404 1m;
                proxy_cache_valid       any 15m;
                proxy_cache_use_stale   error timeout invalid_header updating;

                proxy_http_version 1.1;
                proxy_set_header Connection $http_connection;
                proxy_set_header Origin http://$host;
                proxy_set_header Upgrade $http_upgrade;

Re: The requested URL /nagios/nagios/cgi-bin/status.cgi was

Posted: Fri Oct 27, 2017 9:22 am
by kyang
Sounds great! I'll be closing this topic as resolved!

If you have any more questions, feel free to create another thread!

Thank you for using the Nagios Support Forum!