dongxie2613 2014-02-17 20:58
浏览 1720

如何在nginx中使用_GET参数获得正确的try_files $ uri指令

I just migrated a site from apache to nginx, and am very pleased so far. However, the server doesn't seem to recognize a $_GET parameter.

I've read that the answer is to change the try_files directive to:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

But this isn't working for me. I suspect it's because the query string I'm using is a few directories in, with the url something like:

http://www.mysite.com/thedirectory/thefile?sortby=director

I just can't tweak the try_files directive to work in that instance, and the documentation seems sparse or obsolete.

Any ideas? If I don't get this resolved, I'm going to have to go back to Apache.

  • 写回答

1条回答 默认 最新

  • dpp10181 2014-02-19 17:10
    关注

    I don't know where you got that answer from,but in the context of your problem I don't see the relevance. Let's first get something clarified:

    1. Try_files looks to match the URI with a physical location on disk and allows you to control the fallback action.
    2. The default fallback is to throw a 404.
    3. $query_string is not relevant to the matching process. It is used for try_files constructs where something has to be added to the query string.

    There are three possible causes and remedies for your problem:

    1. The uri matches a real file, but without the file extension, which causes the php processing location to not get triggered. In this case your statement should be:

      try_files $uri $uri/ $uri.php;

    2. This is a virtual location and the router is in index.php, like it it's with many applications, like WordPress and Magento. In this case the try_files should be:

      try_files $uri $uri/ @appname;

    Without more context providing a location block for @appname is not possible.

    1. You are not including relevant fastcgi_param directives. In this case your try_files is noise. Fix the actual problem first, by including the provided example fastcgi_param, as mentioned in the comments.
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题