【问题标题】:Can't combine alias with fastcgi_cache in Nginx无法在 Nginx 中将别名与 fastcgi_cache 结合使用
【发布时间】:2013-08-27 02:55:13
【问题描述】:

这行得通:

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 可以正常工作。

【问题讨论】:

    标签: php nginx


    【解决方案1】:

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

    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_cache) .

    【讨论】:

      猜你喜欢
      • 2017-09-29
      • 1970-01-01
      • 2011-07-02
      • 2019-07-15
      • 1970-01-01
      • 2018-10-05
      • 2019-01-25
      • 2021-02-05
      • 2022-12-18
      相关资源
      最近更新 更多