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

如何在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 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line