Ningx/Django Bad Request Error

Henry Ward henry.ward at secondsightco.com
Wed Jan 18 00:35:40 UTC 2012


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;
        }

}




More information about the nginx mailing list