Nginx

在 nginx 中為 cacti 指定子域的目錄位置

  • February 4, 2019

我正在嘗試使用以下配置使 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/這不是我想要的。有人可以告訴我我在這裡缺少什麼嗎?謝謝你的幫助!

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

$url_path = '/cacti/';

用斜線替換值解決了這個問題。

引用自:https://serverfault.com/questions/952225