本文介绍了子文件夹中的 NGINX try_files 发送到 php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何让 nginx 尝试在子文件夹中查找文件,否则将其请求发送到要处理的 php 文件,例如:

I am trying to figure out how to get nginx to try and find a file in a subfolder, otherwise send it's request to a php file to be handled, for example:

请求的文件:http://somesite.com/css/style.css实际文件:http://somesite.com/content/css/style.css

requested file: http://somesite.com/css/style.cssactual file: http://somesite.com/content/css/style.css

location /mycms/ {
  try_files /mycms/content/$uri /mycms/content/$uri/ /mycms/index.php?$args;
}

但这不起作用,有关如何实现这一目标的任何建议?

But this does not work, any suggestions on how I can achieve this ?

推荐答案

你以错误的方式使用了 $uri,试试这个

you're using $uri in a wrong way, try this instead

location ~ /mycms/(.*) {
  try_files /mycms/content/$1 /mycms/content/$1/ /mycms/index.php?$query_string;
}

这篇关于子文件夹中的 NGINX try_files 发送到 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 06:08