Reputation: 96
Here is the .ini file:
module=myapp.wsgi:application
master=True
pidfile=/tmp/project-master.pid
socket=127.0.0.1:8000
vacuum=True
max-requests=5000
daemonize=/home/mercier/django/site/wsgi.log
buffer-size=327680
processes=16
listen=500
timeout=10
post-buffering=1
nginx forwards the connection using uwsgi_pass directive.
No post data is seen from django - the request.POST is just {}. This is a huge problem... How can I fix this? Post data was seen in the development (runserver).
Important note: both nginx and wsgi respond with 200 (OK). I also tried to set different post-bufferings (as found here and there), but no difference...
django 1.4 uwsgi 1.9.15 nginx 1.2.1
EDIT3: Now I try to use webob: (load request.environ) The client disconnected while sending the POST/PUT body (39 more bytes were expected)
Now I try manually: print request.environ['wsgi.input'].read(39) -> is an empty line...
Edit4: by not I tried just about any hint I found on the net, I'm considering trying fcgi or deploying it on a runserver ;(
Edit5: relevant nginx.conf (enabled site) section:
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location / {
root /var/www;
index index.html index.htm;
proxy_set_header X-FORWARDED-FOR $remote_addr;
include uwsgi_params;
uwsgi_pass_request_body on;
uwsgi_pass_request_headers on;
uwsgi_pass 127.0.0.1:8000;
}
uwsgi_params:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
uwsgi_param DOCUMENT_BODY $request_body;
Edit6:
This is the application (module=) I'm using:
import os,sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "site.settings")
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
"../../")))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
"../")))
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Upvotes: 1
Views: 4566
Reputation: 96
x=request.body
This should be the first line in any django app ran by wsgi. Then POST DATA works. Django just must read the body of request immediately if it is used later.
However, there still is this problem: invalid uwsgi request (current strsize: 16705). skip.
So I it is difficult to use uwsgi in this setting. I solved this by the use of fcgi, which does not have such limits.
Justification: strsize is not configurable -- http://comments.gmane.org/gmane.comp.python.wsgi.uwsgi.general/5712
Edit: Roberto is right -- strsize is unrelated to request's body and it WORKS even in uwsgi. Debugging a problem during travelling, nights etc is not always a good idea ;) However, Django must read the body request immediately and this is beyond doubt. The request's body must be read prior doing anything else.
Upvotes: 0
Reputation: 12933
Try removing nginx to see where the problem is. Run uWSGI in http mode:
http-socket=127.0.0.1:8000
and connect to port 8000
if all works, ensure nginx is passing the CONTENT_LENGTH parameter
Eventually paste your nginx config
Upvotes: 1