Ningx/Django Bad Request Error

Henry Ward henry.ward at secondsightco.com
Wed Jan 18 16:58:48 UTC 2012


Thanks Xav and Valentin for the quick response.  Sorry - I have to copy your responses because I was subscribed on digest rather than real-time email.  But I am now on the normal mailing list.

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:

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

In that the also had the same problem that Bad Request nothing shows in the error log.  I thought it might be a similar issue but I don't have any spaces in python urllib2 header so I don't think that is the issue.

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.

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.

I'm stumped.

WSGI
Xav - I am happy try gunicorn.org as a wsgi server instead of fcgi.  Particularly if there isn't a reasonable solution to this problem.  Again - I'm now to this.  Can you give a quick background on why you don't recommend fcgi and do recommend gunicorn?  (current. problem excluded ;-)

Henry


On Jan 17, 2012, at 4:35 PM, Henry Ward wrote:

> Hello Nginx Group.
> 
> I am new to Ngnix and installing my first Nginx/Django server.  I've been struggling with a Bad Request 400 Error for two days now and I have nowhere else to go.  Here is the problem:
> 
> I have Nginx configured with django.  My default config file is below.  I am have a basic django-piston REST service setup that works correctly with django's runserver.  The following two commands work perfectly with django's runserver http server:
> 
> url = 'http://localhost/receipts'
> # GET receipts data
> req = urllib2.Request(url)		
> f = urllib2.urlopen(req)
> 
> # POST Receipts data with json data
> data = <json data...>
> req = urllib2.Request(url, data=data, headers={'Content-Type': 'application/json'}) 	
> f = urllib2.urlopen(req)
> 
> When I run the same requests against my nginx installation the GET function works just fine.   However, the POST request returns a HTTP Error 400: BAD REQUEST error.  
> 
> It is exactly the same code and I know this is working with the django runserver.  It must be some configuration in Nginx that is regecting the POST request.  I get that error for any Content-Type.  
> 
> I have looked everywhere and I cannot find anything about allowing this post request.   I hope someone here can help nudge me in the right direction.  My Nginx config file settings is below.  I have modified many variables like buffer sizes and body sizes and it is not that.  The data I'm posting is less than 8k.  
> 
> Any ideas?
> 
> ----------------------------
> 
> server {
>        include mime.types;
>        default_type application/json;
> 
>        client_body_buffer_size 1200K;
>        client_header_buffer_size 1200K;
>        client_max_body_size 2m;
>        large_client_header_buffers 2 1200K;
> 
>        listen   80; ## listen for ipv4; this line is default and implied
>        #listen   [::]:80 default ipv6only=on; ## listen for ipv6
> 
> 
>        # Make site accessible from http://localhost/
>        server_name localhost;
> 
>        # Log information
>        access_log /home/henry/logs/access.log;
>        error_log /home/henry/logs/error.log;
> 
>        root /home/henry/webservice/public;
> 
>        location /site_media
>        {
>                root /path/to/yoursite.com/public;
>        }
> 
>        location / {
>                        # host and port to fastcgi server
>                        fastcgi_pass 127.0.0.1:8081;
>                        fastcgi_param PATH_INFO $fastcgi_script_name;
>                        fastcgi_param REQUEST_METHOD $request_method;
>                        fastcgi_param QUERY_STRING $query_string;
>                        fastcgi_param SERVER_NAME $server_name;
>                        fastcgi_param SERVER_PORT $server_port;
>                        fastcgi_param SERVER_PROTOCOL $server_protocol;
>                        fastcgi_param CONTENT_TYPE $content_type;
>                        fastcgi_param CONTENT_LENGTH $content_length;
>                        fastcgi_pass_header Authorization;
>                        fastcgi_intercept_errors off;
>        }
> 
>        location /doc {
>                root /usr/share;
>                autoindex on;
>                allow 127.0.0.1;
>                deny all;
>        }
> 
>        location /images {
>                root /usr/share;
>                autoindex off;
>        }
> 
> }
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20120118/f389fc00/attachment-0001.html>


More information about the nginx mailing list