为 Cacti 的 nginx 子域名指定目录位置

为 Cacti 的 nginx 子域名指定目录位置

我正在尝试让 Nginx 从子域提供 Cacti(一个 php 监控应用程序),使用以下配置:

  server {
    listen 80;
    server_name cacti.mydomain.net;
    return 301 https://$server_name$request_uri;
  }

  server {
    listen 443 ssl;
    server_name cacti.mydomain.net;
    root /usr/share/webapps/cacti;

    index index.php;
    charset utf-8;

    location ~ \.php?$ {
      include /etc/nginx/fastcgi_params;
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    access_log /var/log/nginx/cacti.access.log main;
    error_log /var/log/nginx/cacti.error.log warn;

    include ssl.conf;
  }

然而,当我去https://cacti.mydomain.net/,Nginx 返回 404。错误日志显示如下行:

[error] 41809#41809: *26 open() "/usr/share/webapps/cacti/cacti/include/themes/modern/images/cacti_logo.gif" failed (2: No such file or directory), client: 83.162.2.169, server: cacti.mydomain.net, request: "GET /cacti/include/themes/modern/images/cacti_logo.gif HTTP/2.0"

看起来请求正在发送到文件所在的位置,但它试图从错误的位置打开它(cacti/cacti/include/...)

我尝试了不同的位置块,但这会将 URL 更改为https://cacti.mydomain.net/cacti/这不是我想要的。有人能告诉我我这里漏掉了什么吗?非常感谢你的帮助!

答案1

/usr/share/webapps/cacti/include/config.php 中的配置似乎包含此行:

$url_path = '/cacti/';

用斜线替换值即可解决问题。

相关内容