![cgi-bin 没有被 nginx 代理用于 nagios 主机](https://linux22.com/image/760584/cgi-bin%20%E6%B2%A1%E6%9C%89%E8%A2%AB%20nginx%20%E4%BB%A3%E7%90%86%E7%94%A8%E4%BA%8E%20nagios%20%E4%B8%BB%E6%9C%BA.png)
我在 ubuntu 20.04 虚拟机上设置了反向代理 nginx 主机 -> nagios,它们就像默认的 apt-get 安装一样,没有自定义。我添加了自签名证书只是为了测试。
192.168.254.107-nginx 192.168.254.200-nagios
问题是 cgi-bin 似乎没有重定向,并且由 nginx 本身提供服务
Nginx 配置
server {
listen 443 ssl;
listen 80 default_server;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 2m;
location /nagios4 {
proxy_pass https://192.168.254.200/nagios4;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}
错误
2020/12/02 05:08:53 [error] 2307#2307: *21 open() "/usr/share/nginx/html/cgi-bin/nagios4/avail.cgi" failed (2: No such file or directory), client: 192.168.254.163, server: , request: "GET /cgi-bin/nagios4/avail.cgi HTTP/1.1", host: "192.168.254.107", referrer: "https://192.168.254.107/nagios4/side.php"
2020/12/02 05:08:58 [error] 2307#2307: *21 open() "/usr/share/nginx/html/cgi-bin/nagios4/extinfo.cgi" failed (2: No such file or directory), client: 192.168.254.163, server: , request: "GET /cgi-bin/nagios4/extinfo.cgi?type=3 HTTP/1.1", host: "192.168.254.107", referrer: "https://192.168.254.107/nagios4/side.php"
2020/12/02 05:09:02 [error] 2307#2307: *21 open() "/usr/share/nginx/html/cgi-bin/nagios4/extinfo.cgi" failed (2: No such file or directory), client: 192.168.254.163, server: , request: "GET /cgi-bin/nagios4/extinfo.cgi?type=6 HTTP/1.1", host: "192.168.254.107", referrer: "https://192.168.254.107/nagios4/side.php"
2020/12/02 05:09:02 [error] 2307#2307: *21 open() "/usr/share/nginx/html/cgi-bin/nagios4/extinfo.cgi" failed (2: No such file or directory), client: 192.168.254.163, server: , request: "GET /cgi-bin/nagios4/extinfo.cgi?type=0 HTTP/1.1", host: "192.168.254.107", referrer: "https://192.168.254.107/nagios4/side.php"
2020/12/02 05:09:03 [error] 2307#2307: *21 open() "/usr/share/nginx/html/cgi-bin/nagios4/extinfo.cgi" failed (2: No such file or directory), client: 192.168.254.163, server: , request: "GET /cgi-bin/nagios4/extinfo.cgi?type=4 HTTP/1.1", host: "192.168.254.107", referrer: "https://192.168.254.107/nagios4/side.php"
我注意到当我尝试在另一个浏览器中打开时它会去寻找 nginx 主机上的路径......
https://192.168.254.107/cgi-bin/nagios4/status.cgi?hostgroup=all&style=hostdetail
答案1
问题可能出在你的配置中的这两行:
location /nagios4 {
proxy_pass https://192.168.254.200/nagios4;
删除指令nagios4
中location
转发所有位置到代理的 或从指令中
删除。 您可以从错误日志中看到目录和实际 cgi 文件之间出现的类似。/nagios4
proxy_pass
nagios4
cgi-bin
extinfo.cgi
答案2
我发现了同样的问题,虽然它很老了,但仍然适用于 HTTP。我没有尝试过 https,因为我使用的是自签名证书
主要问题是 cgi-bin 仍在 nginx 文件夹/主机上调用,而不是在后端。这解决了该问题并将调用重定向到后端。
location /cgi-bin/nagios3/ {
proxy_pass https://nagios.localdomain.com/cgi-bin/nagios3/;
proxy_redirect default;
}
location /nagios3/ {
proxy_pass https://nagios.localdomain.com/nagios3/;
proxy_redirect default;
}
location /nagios/ {
proxy_pass https://nagios.localdomain.com/nagios3/;
proxy_redirect default;
}