我正在尝试在nginx docker容器中设置具有IP白名单的Basic-Auth。但是由于"proxy_set_header X-Real-IP $remote_addr;"
,nginx似乎无法正常处理远程IP地址
最好的方法是什么?
我已经尝试设置:
proxy_set_header REMOTE_ADDR $remote_addr;
和:
set_real_ip_from xxx.xxx.xxx.xx;
real_ip_recursive on;
upstream django {
server django:8000 fail_timeout=0;
}
server {
listen 80 default_server;
#server_name localhost;
location ^~ /media {
alias /usr/share/nginx/html;
autoindex on;
}
location / {
try_files $uri @django_proxy;
satisfy any;
allow 212.xxx.xxx.26;
allow 212.xxx.xxx.239;
allow 192.168.99.30;
deny all;
auth_basic "authentication required";
auth_basic_user_file /srv/.htpasswd;
}
location @django_proxy {
fastcgi_read_timeout 300;
proxy_read_timeout 300;
set_real_ip_from 212.xxx.xxx.26;
real_ip_recursive on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_pass http://django;
proxy_set_header REMOTE_ADDR $remote_addr;
}
}
实际结果是,它始终显示基本身份验证
预期结果将是在办公室中没有基本身份验证