Ningx/Django Bad Request Error - Full Solution

Henry Ward henry.ward at secondsightco.com
Wed Jan 18 20:12:36 UTC 2012


Found the problem.  A percent symbol snuck into the json data and I was having the same problem as below:

http://www.ruby-forum.com/topic/2573586

Other servers are more forgiving but Nginx was choking on urllib2's handling of escaping the % symbol.  

Sorry for the long winded discussion.

Henry

On Jan 18, 2012, at 9:54 AM, Valentin V. Bartenev wrote:

> On Wednesday 18 January 2012 20:58:48 you wrote:
> [...]
>> Error Log
>> The error log shows nothing.  Literally.  The access_log shows the access
>> url and the 400 error.  But the error log does not.  I know that is hard
>> to believe its similar to what is said here:
>> 
> 
> Did you set a correct path to error log in main context (not that one in your 
> server section) and debug level? Did you configure and build nginx with debug?
> 
> [...]
>> This is what makes so irritatingly difficult to debug.  It is also I feel
>> it some type of permission error or setting that does not allow POST
>> requests.  I've also read here (https://calomel.org/nginx.html) that Nginx
>> by default only allows GET requests but I couldn't find anywhere where the
>> is verified nor how to enable that.
> 
> https://calomel.org/nginx.html
> ## Only allow GET and HEAD request methods. By default Nginx blocks
> ## all requests type other then GET and HEAD for static content.
> 
> If you read carefully, you will notice "for static content". That means files in 
> your filesystem, obviously, cuz they can't process POST.
> 
> Actually, I expect that you POST request is just broken. It's ok for primitive 
> django builtin http-server, but it isn't acceptable for nginx. 
> 
> Why don't you use simple curl for emulate request? Please, try curl.
> 
> Or, it may be a django error, cuz of misconfigured fastcgi-param.
> Why don't you use stock fastcgi-params config that distributed with nginx? 
> 
> [...]
>> I have also created application logging in Django and have "GOT HERE" log
>> statement in the first line of the view that handles the POST request.. 
>> That line never gets called so it appears Nginx is kicking out the request
>> before it ever passes to the django app.
> 
> No. It just means that your request didn't reach the view, that handles POST 
> requests. Probably, because of misconfigured fastcgi-param django receive wrong
> or incomplete params.
> 
> Anyway, please, investigate and fix your problem with debug log. There's no 
> magic.
> 
> wbr, Valentin V. Bartenev



More information about the nginx mailing list