在我看来,我不太了解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;
}
如何将变量传递给应用服务器?