2

I have nginx 1.0.2 installed on Ubuntu 11 with php 5.3.5 running with FPM/FastCGI.

On a codeigniter applilcation of mine i get the following problem. I have a simple login form with a username and password field. When I submit the form the $_POST array is empty. So is $this->input->post('username') and $this->input->post('password').

The application works fine on apache. I tried creating a simple test form on a simple php file and $_POST data worked perfectly. I can provide configuration files if needed. Any ideas ?

Update: It finally worked. There were some redirects in my vhost config which were causing loss of post data. The working vhost config can be found here: http://codeigniter.com/forums/viewthread/90231/#455528

VangelisB
  • 438
  • 5
  • 10
  • Do you have fastcgi_pass_request_body off; anywhere in your config? Is there anything in the error log about failing to open a temporary file for the request body? – kolbyjack May 19 '11 at 00:49
  • No, fastcgi_pass_request_body is not found in any config or vhost file. I don't get such a "temporary file" error in the log but I do get a 404 error header from the form's target URL. /user/login/ displays the form and the same controller/method parses the results as well. However the 404 is in the header only when the form is submited. I guess a redirect rule causes the error. I used the redirect rules from this guy http://bit.ly/kljKty The rest of nginx configuration is just the default stuff. To be honest I'm not that deep into redirect rules to make sense of every line in that config. – VangelisB May 19 '11 at 08:55
  • You're getting a 404? How are you verifying that the fields are empty? A 404 sounds more like the form isn't getting processed at all. – kolbyjack May 19 '11 at 12:50
  • Through firebug. With print_r($_POST); The form is processed but the validation fails since $_POST is empty. Could you share a working vhost configuration (if you got one) of a codeigniter project through a pastebin or something ? – VangelisB May 20 '11 at 18:52

4 Answers4

1

I think I know the issue now. The fact that it's returning 404 and processing your script tells me that the error_page is what's doing the 'rewrite' to get the request to /index.php. An error_page to a non-named location will transform the request into a GET, so the error_page 404 /index.php is doing an internal redirect to /index.php, but it's stripping the request body in the process (and the lack of an = means the status code isn't overridden by the error_page target). I'm not sure why all those ifs aren't performing the redirect (if processing in nginx is really weird, so it's a good idea to avoid them), but I think if you use a named location for your error page, that will preserve the request body and fill in $_POST. Try replacing your current error_page directive with:

location @redir {
  rewrite ^ /index.php;
}
error_page 404 = @redir;
kolbyjack
  • 17,660
  • 5
  • 48
  • 35
0

I had a similar problem and i tried everything mentioned here. It was very simple when i figured it, I had not named my input variables in the form. I had missed the name parameter.

<input type="name" placeholder="Name" name="name">
0

check these:

<form method="post">

you using the post method?

try running the profiler:

$this->output->enable_profiler(TRUE);

seeing any POST output there?

phirschybar
  • 8,357
  • 12
  • 50
  • 66
  • Of course i'm using the post method. Like I said above the app works fine on apache. The profiler was a nice idea I havn't thought of but still gives me "No POST data exists". – VangelisB May 18 '11 at 19:05
0

I was using my own PHP framework with similar URI rewrites as CI and on Nginx server had similar issues, cause my forms had actions like: action="admin/login/post" and I had to change them to end with .php action="admin/login/post.php" so they could work, but this requires you to change the URI rewrite of your CI class to replace that .php from the uri string.

zokibtmkd
  • 2,173
  • 1
  • 22
  • 24