Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http auth with nginx and uwsgi #29

Closed
gensmusic opened this issue Oct 30, 2015 · 4 comments
Closed

http auth with nginx and uwsgi #29

gensmusic opened this issue Oct 30, 2015 · 4 comments

Comments

@gensmusic
Copy link

Recently I use flask + uwsgi + nginx to make a server and I use Flask-HTTPAuth
to do the digest auth in flask.
Most ot time it works fine but when I do a large post (let's say 3M) then I got 502 error in browser.
nginx error:

[error] 3438#0: *16 sendfile() failed (32: Broken pipe) while sending request to upstream, client: 203.100.xx.xx, server: xxxx.net, request: "POST /create_invitation HTTP/1.1", upstream: "uwsgi://unix:/xxxxr/uwsgi.sock:

I search a lot on google to solve it but didn't success until I close the http auth.
And it works well now. So should I move http auth from flask to nginx ?

I guess flask-httpauth close the connection after it sends 401 ? So nginx got error ?

thanks

@gensmusic
Copy link
Author

And also a lot of this errors in nginx:

2015/10/30 04:29:20 [error] 4021#0: *129 readv() failed (104: Connection reset by peer) while reading upstream, client: 203.100.xx.xx, server: xxx.net, request: "POST /create_invitation HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031"

@miguelgrinberg
Copy link
Owner

Are there any errors, crashes or stack traces printed by the Flask process?

@gensmusic
Copy link
Author

No. nothing. Flask is normal. Uwsgi is normal too. I can see flask return a 401 to client from uwsgi log.
But client ends up no response. Some answers in google says it's maybe because uwsgi or flask close the connection before it reads the post body, therefore nginx can't read from uwsgi. I just want to know if http-auth will cause this situation. I use http-auth digest in app_before_request for every request.

If request is GET, it's ok.
but when I use post to upload files, this happens a lot.

@gensmusic
Copy link
Author

I think I found the issue. We are using Alomofire to send http request. And there is no header "connection:keep-alive". After we add this header, it works now.
I think the reason might be:
app -> post -> nginx ->uwsgi->http-auth
return 401, no keep-alive, close connection
error, read from uwsgi
Maybe nginx is keepiing alive but flask or uwsgi just close the connection because there is no keep-alive header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants