Nginx:如何从htpasswd授权中排除含有查询参数的URL

一个WordPress站点通过使用htpasswd的HTTP授权来保护/wp-login.php。 Web服务器是Nginx。 下面给出相同的configuration。

与插件关联的URL使用wp-login.php?查询参数来pipe理外部用户。 url的例子是:
http://beta.timepass.com/wp-login.php?action=wordpress_social_authenticate&mode=login&provider=Facebook

我只需要允许那些匹配查询参数action=wordpress_social_authenticate URL绕过htpasswd。 我已经尝试了一些东西,但无处可去! Nginx在if条件下不会将auth_basic "off"

Nginxconfiguration参考:

 server { listen 80; server_name beta.timepass.com; root /var/www/projects/beta.timepass.com; index index.php index.html index.htm; autoindex off; access_log /var/log/nginx/beta.timepass.com-access.log; error_log /var/log/nginx/beta.timepass.com-error.log; try_files $uri $uri/ /index.php?$args; ## Disallow direct access to wp-login.php location ~* ^/wp-login.php { #satisfy any; #allow 192.168.1.0/24; allow 192.168.1.157; auth_basic "Site Needs You to Authenticate"; auth_basic_user_file /etc/nginx/htpass-beta ; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { expires off; ## Do not cache dynamic content #add_header Pragma public; #add_header Cache-Control "public, max-age=300"; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/projects/beta.timepass.com$fastcgi_script_name; fastcgi_read_timeout 60s; } } 

你应该使用一个映射 ,因为auth_basic指令允许variables的使用。

例如 :

 map $arg_action $auth { default "Site Needs You to Authenticate"; "wordpress_social_authenticate" "off"; } server { [...] location ~* ^/wp-login.php { auth_basic $auth; auth_basic_user_file /etc/nginx/htpass-beta ; [ ...] } }