2017-07-15 215 views
1

如何在NGINX auth_basic在同一台服务器上成功后设置Cookie并重定向?设置cookie并在nginx基本验证成功后重定向

这似乎需要一些组合satisfy,auth_basicauth_request,但文档仅涵盖身份验证外包给某些外部服务器的情况。 预先感谢您。

回答

0

我觉得应该有更好的方法,但如果你使用内部位置,你可以欺骗try_files为你做这件事。

location /cookie-drop { 
    auth_basic "Please authenticate"; 
    auth_basic_user_file /your/htpasswd/file; 
    # Using null as a hardcoded nonexistent file 
    try_files null @cookie-drop; 
} 

location @cookie-drop { 
    internal; 
    add_header Set-Cookie "token=foo;Domain=example.com;Path=/"; 
    return 302 https://$host/ 
} 

如果你把return 302/cookie-drop位置内,它会忽略auth_basic设置。 try_files设置是我能找到的重定向到像这样的内部位置的唯一的设置。也许有更好的方法。

相关问题