-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
nixos/nginx: add locations."name".uwsgiPass option and use it #346776
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I haven't checked, but I assume you can't have both proxyPass
and uwsgiPass
in the same location?
If so, we'll probably want an assertion checking for this?
Probably, I added one. |
I think you pushed that to the wrong PR. |
45dad5a
to
be26ca8
Compare
Pushed the assertion to this PR and added the if blocks for proxyResolveWhileRunning. |
be26ca8
to
be91974
Compare
@ofborg eval |
I'm a little surprised the |
be91974
to
7109748
Compare
7109748
to
6443f16
Compare
${command} X-Forwarded-For $proxy_add_x_forwarded_for; | ||
${command} X-Forwarded-Proto $scheme; | ||
${command} X-Forwarded-Host $host; | ||
${command} X-Forwarded-Server $host; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for missing this before, but when taking a look at ${pkgs.nginx}/conf/uwsgi_params
, I see:
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
Are you sure uwsgi_param
is the correct thing here?
For instance, https://stackoverflow.com/questions/51207346/missing-nginx-headers-in-uwsgi-application-flask/51207405#51207405 says that you'd have to prefix the values here with HTTP_
.
EDIT: according to pallets/werkzeug#1465 (comment) it also must be all uppercase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I must admit I didn't e2e test this with my other branch since creation. 😓
6443f16
to
1c3b6f3
Compare
Just deployed this on top of #346777 and things are working as they should. |
Apologies, I have this tab open, will try to review soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you also test the combination with recommendedUwsgiSettings
?
Because if I do so for mailman, I get
machine # [ 53.922668] env[1344]: Traceback (most recent call last):
machine # [ 53.923586] env[1344]: File "/nix/store/p08j09lli1w0y8gk7j5mzvxd1m5v9nwj-python3-3.11.9-env/lib/python3.11/site-packages/django/core/handlers/wsgi.py", line 123, in __call__
machine # [ 53.925868] env[1344]: request = self.request_class(environ)
machine # [ 53.926829] env[1344]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^
machine # [ 53.927734] env[1344]: File "/nix/store/p08j09lli1w0y8gk7j5mzvxd1m5v9nwj-python3-3.11.9-env/lib/python3.11/site-packages/django/core/handlers/wsgi.py", line 71, in __init__
machine # [ 53.929852] env[1344]: self.method = environ["REQUEST_METHOD"].upper()
machine # [ 53.930968] env[1344]: ~~~~~~~^^^^^^^^^^^^^^^^^^
machine # curl: (22) T[ 53.933110] env[1344]: KeyError: 'REQUEST_METHOD'
By adding all uwsgi params by hand with
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 REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
I fixed the problem (REQUEST_METHOD wasn't alone, I triggered a redirect loop then on a curl against localhost
).
So apparently nginx somewhere sets those defaults and our declaration discards these settings?
I think this also means that the global recommendedUwsgiSettings
isn't really functional since it gets overwritten by whatever level sets the uwsgi params I shared above.
I think I forgot that. 🙈 When enabling it for searxng, I get a very similar error.
Yeah, we include |
1c3b6f3
to
d1a28bb
Compare
So, I fixed a typo in |
yeah those are the nginx defaults:
super stupid behaviour by nginx, but, you can do the |
uwsgi_param HTTP_HOST $host; | ||
uwsgi_param HTTP_X_REAL_IP $remote_addr; | ||
uwsgi_param HTTP_X_FORWARDED_FOR $proxy_add_x_forwarded_for; | ||
uwsgi_param HTTP_X_FORWARDED_PROTO $scheme; | ||
uwsgi_param HTTP_X_FORWARDED_HOST $host; | ||
uwsgi_param HTTP_X_FORWARDED_SERVER $host; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused why these are needed and if anything even would use them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uwsgi_params are generally used by uwsgi and/or its plugins, not directly accessed by applications. Some of the very specific use-cases are here https://uwsgi-docs.readthedocs.io/en/latest/Nginx.html
I can't say the above params are recommendedUwsgiConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are basically a mapping of the proxy_pass variables.
Yep |
@Ma27 how do we want to proceed here? |
I'll try to get to another review soonish :) |
I am going to use that in another PR for searxng #346777 to reduce duplication for uwsgi.
This also allows to easily overwrite a uwsgi_pass target with an upstreams block.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.