-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Gunicorn w/ Django on nginx + unix socket: REMOTE Adress is "b''" (a string containing the three characters b'') #1755
Comments
edit: I've added several details into the ticket. |
I've tried this locally with Python 3.6 and |
I'll try to provide a docker setup where this bug happens, stay tuned. |
I've created an example repo: Feel free to check it out, it should be easy to reproduce. |
This issue seems to be appearing with Python 3.5. Python 3.6.0 also has this issue. |
It seems like this issue is related to the python version, rather than gunicorn. Affected Versions: Non-affected versions: I'm just making an educated guess here, but I believe that python issue 30205 is the cause (patch has been included with Python 3.5.4 and Python 3.6.2). I'm not 100% sure if you can fix this in gunicorn. However, the problem is appearing on a debian 9.4, so this issue is probably affecting quite a bunch of users. |
Fix for #1755: Decode remote addr if it is a byte
Closed by #1769. |
|
I just had a huge "wtf moment" when I was setting up a Django Middleware to parse the
HTTP_X_FORWARDED_FOR
header. For security reasons (more a precaution) my middleware would check the content of theREMOTE_ADDR
header, to verify that the request is actually coming from a trusted proxy (e.g., 127.0.0.1).Now, as already discussed in issue #797 gunicorn does not provide the
REMOTE_ADDR
anymore when used with an unix socket, and instead an empty string is being sent (see comment by @benoitc on Oct 9, 2014: "To summarise the context, the remote address is right now empty by default when using the unix socket. ").So I thought I'll just make this little thing in a Django Middleware:
Oh well... It seems that I was wrong.
Would you like to know what
request.META['REMOTE_ADDR']
contains? It's actually the three charactersb''
(no, not the byte representation b'', but actually the three characters!).I believe this is not the intended behaviour, though I'm not involved enough with the whole gunicorn/nginx unix socket setup to point out where the error might be.
Here are some Details of the software that is being used:
Gunicorn is started via systemd with the following command:
gunicorn --workers 3 --bind unix:/run/gunicorn/socket application.wsgi
Nginx is configured as follows:
The text was updated successfully, but these errors were encountered: