在我看来,我不太了解 REMOTE_USER 变量。我有三个基于不同主机的实例:nginx、django_auth_server、django_app_server。我正在尝试实现“单点登录”:用户通过 nginx 登录到 django_auth_server,被重定向到 django_app_server 并继续冲浪而无需身份验证。在我重定向到根文件夹后(从“/login”到“/”),REMOTE_USER 变量为空。但它确实存在于请求标头中:
Content-Type: text/html; charset=utf-8
Location: /
REMOTE_USER: alfabeta
X-Frame-Options: SAMEORIGIN
Vary: Cookie
Content-Length: 0
Set-Cookie: csrftoken=...
Set-Cookie: sessionid=...
授权视图中的代码(djangoauth 实例):
if user is not None:
login(request, user)
r = redirect('/')
r['REMOTE_USER'] = username
return r
我不确定以这种方式设置变量是否正确。
nginx 配置的一部分
server {
listen 8080 default_server;
server_name localhost;
charset utf8;
autoindex off;
underscores_in_headers on;
proxy_pass_request_headers on;
...
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass uwsgiapp;
uwsgi_read_timeout 300;
uwsgi_param Host $host;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
}
location =/login/ {
include /etc/nginx/uwsgi_params;
uwsgi_pass uwsgiauth;
uwsgi_read_timeout 300;
uwsgi_param Host $host;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
uwsgi_param REMOTE_USER $remote_user;
}
如何将变量传递给应用服务器?