3

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.

dilettante
  • 381
  • 1
  • 4
  • 19
  • 1
    The answer seems to be in my fastcgi_params. I added this, which worked for a few minutes before crashing my server. Location config: location / { try_files $uri $uri/ /index.php?$query_string; fastcgi_param QUERY_STRING $query_string; } – dilettante Feb 17 '14 at 21:55
  • 1
    You don't `include fastcgi_params` in your php block ? – Mohammad AbuShady Feb 17 '14 at 22:31

1 Answers1

0

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.