我这里测试没有问题
配置如下
worker_processes 1;
events {
worker_connections 1024;
}
http {
req_status_zone server "$host,$server_addr:$server_port" 10M;
req_status_zone_add_indicator server $limit;
server {
listen 18080;
location /us {
auth_basic "nginx basic http test for ttlsa.com";
auth_basic_user_file conf/htpasswd;
req_status_show;
req_status_show_field req_total $limit;
}
set $limit 0;
if ($arg_limit = '1') {
set $limit 1;
}
req_status server;
}
}
Chrome version: 64.0.3282.186 (Official Build) (64-bit)
测试页面返回:
这条请求对应日志:*** - - [07/Mar/2018:23:32:34 +0800] "GET /us HTTP/1.1" 401 659 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36")
如果你直接访问/us返回的是401就说明模块和配置没有异常 (如果浏览器还是无法提升密码输入框,可能是浏览器自身问题)
$ curl localhost:18080/us -i
HTTP/1.1 401 Unauthorized
Server: Tengine/2.2.2
Date: Wed, 07 Mar 2018 15:34:14 GMT
Content-Type: text/html
Content-Length: 654
Connection: keep-alive
WWW-Authenticate: Basic realm="nginx basic http test for ttlsa.com"
401 Authorization Required401 Authorization Required
This server could not verify that you are authorized to access the document requested. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!
URL: | http://localhost:18080/us |
Server: | e100069206110.zmf |
Date: | 2018/03/07 23:34:14 |
Powered by Tengine/2.2.2