无法将别名与 Nginx 中的fastcgi_cache结合使用



这很有效:

location ~ ^/special/(.+.php)$ {
  alias /var/special/$1;
  try_files "" =404;
  include fastcgi_params;
  fastcgi_pass 127.0.0.1:9000; # php-fpm socket
}

但事实并非如此:

location ~ ^/special/(.+.php)$ {
  alias /var/special/$1;
  try_files "" =404;
  include fastcgi_params;
  fastcgi_pass 127.0.0.1:9000; # php-fpm socket
  fastcgi_cache mycache;
}

如果我试图转到URL"/special/index.php",我会在浏览器中得到一个"找不到文件"文本,我认为它来自php-fpm或php。我在Nginx日志中得到了这个错误:

FastCGI sent in stderr: "Primary script unknown", client: 202.179.27.65, server: myserver.org, request: "GET /special/index.php HTTP/1.1", host: "myserver.org"

知道为什么添加fastcgi_cache会破坏这个吗?

请注意,当我使用不使用别名的位置时,fastcgi_cache可以正常工作。

经过几天(!)的摆弄,这种变体似乎起了作用:

location ~ ^/special(/.+.php)$ {
  root /var/special;
  try_files "" =404;
  include fastcgi_params;
  fastcgi_pass 127.0.0.1:9000; # php-fpm socket
  fastcgi_cache mycache;
  fastcgi_param SCRIPT_FILENAME $document_root$1;
  fastcgi_param SCRIPT_NAME $1;
}

区别似乎在于1)使用"root",这似乎是fastcgi_cache所需要的;2)显式设置SCRIPT_FILENAME和SCRIPT_NAME,因为否则"root"将无法工作(即使没有fastcgi_che)。

最新更新