nginx的try_filesredirect尾部的斜杠和403禁止

我试图创build一个组合“超级caching” – >文件 – >模块模式与try_files(“超级caching”从wordpress超级caching采取,因为它是一个类似的方法)。

适用于caching的文件位于“caching”文件夹内。

如果文件存在于其中一个位置,则应该提供该文件。

  1. / $caching$ URI
  2. / $caching$ URI /
  3. $ URI
  4. $ URI /

1.cache – > 2.file – > 3.pattern

location / { try_files /$cache_dir$uri /$cache_dir$uri/ $uri $uri/ /index.php; } 

地址为“domain.com/css/style588.css”的示例

  1. 寻找/srv/www/domain.com/public_html/cache /css/style588.css
  2. 寻找/srv/www/domain.com/public_html/cache /css/style588.css /index.html&.php
  3. 寻找/srv/www/domain.com/public_html /css/style588.css
  4. 寻找/srv/www/domain.com/public_html /css/style588.css /index.html&.php
  5. 如果没有find:/srv/www/domain.com/public_html /index.php

我试图使它与下面的configuration工作。 我究竟做错了什么?

包括来自nginx.conf的domain.conf

 server { ## index index.html index.php (defined in http block, works) server_name domain.com; root /srv/www/domain.com/public_html; ## cache directory ## set $cache_dir 'cache'; ## no cache if post ## if ($request_method = POST) { set $cache_dir 'null dir'; } ## 1.cache -> 2.file -> 3.pattern ## location / { try_files /$cache_dir$uri /$cache_dir$uri/ $uri $uri/ /index.php; } ## .php (set cgi.fix_pathinfo=0 in php.ini, especially if php is on another machine) ## location ~ \.php$ { try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } 

我尝试使用上面的configuration示例

domain.com:(403禁止)

public_html/index.php 不提供。

domain.com/non_existing_folder:(OK

public_html/index.php 服务。

domain.com/folder_exists_in_cache/ 🙁确定)

public_html/cache/folder_exists_in_cache/index.html

domain.com/folder_exists_in_cache 🙁redirect)(无尾随斜线)

redirect标题301永久。 public_html/cache/folder_exists_in_cache/index.html

但url显示为domain.com/cache/folder_exists_in_cache/

uri domain.com/cache/existing_empty_folder 🙁 403禁止)

public_html/index.php 不提供。

我如何避免403禁止(和没有结尾的斜杠,但该文件夹存在cachingredirect?)

已尝试对文件夹设置权限,结果相同。

谢谢你的帮助!

这应该工作:

  location ~ \.php$ { try_files $uri =404; ... } location = / { try_files /nonexistent /index.php?q=$uri&$args; } location / { try_files $cache_dir$uri $cache_dir$uri/index.html $uri $uri/index.html /index.php?q=$uri&$args; }