8

I installed nginx on Ubuntu Hardy and immediately realized that the PHP scripts were getting empty request arrays, ie whether GET or POST nothing was coming through, even the $_REQUEST array was empty.

When I switch back to Apache it was all fine.

The installation nginx version is 0.6.35-0ubuntu1.1~hardy1 and PHP is PHP Version 5.2.4-2ubuntu5.10.

What could be wrong?

3
  • Are you using rewrite or redirect rules?
    – ircmaxell
    Aug 16, 2010 at 15:40
  • No, there is not rewrites or redirects
    – vfclists
    Aug 16, 2010 at 17:46
  • This can also happen if there is a folder with the same name as the path being redirected if mod_rewrite or equivalent exists. The GET parameters get swallowed in that case. Check for a matching folder name if using apache.
    – MyStream
    Mar 14, 2019 at 12:01

4 Answers 4

6

Check if this set in your "location"-section for your fastcgi-module

 fastcgi_param  QUERY_STRING     $query_string;

http://wiki.nginx.org/NginxHttpFcgiModule

1
  • I disable the basic fastcgi_params file from inclusion, because I didn't know how may were needed. Worth learning about though.
    – vfclists
    Aug 16, 2010 at 20:33
7

It's a feature of the try_files command in nginx that the query_string is not passed automatically to the rewritten file but instead must be passed explicitly. Because of this _$SERVER['QUERY_STRING'] is always empty, and so the the variables $_REQUEST and $_GET are also not set.

From the Nginx documentation:

Unlike with rewrite, $args are not automatically preserved if the fallback is not a named location. If you need args preserved, you must do so explicitly:

try_files $uri $uri/ /index.php?q=$uri&$args;

or with just the arguments

try_files $uri $uri/ /index.php?$args;

If you want to guarantee to get the original arguments then use $query_string which is the same as $args except that $query_string is read-only.

0

Try to check the variables_order in php config file used by nginx.

1
  • The variables_order is EGPCS. It is set to the default
    – vfclists
    Aug 16, 2010 at 17:47
0

It can happen if Apache has LimitRequestBody (see core) or SecRequestBodyLimit (see mod_security) set and the request body is larger than said limit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .