非拉丁 HTTP 基本身份验证消息编码/NGINX

Non-latin HTTP Basic Authentication message encoding / NGINX

我想在浏览器的 "HTTP Basic Authentication" 提示符中显示西里尔文消息,但最终会出现胡言乱语。

这是我的 NGINX 配置:

server {
  charset utf-8;
  listen 80;
  server_name example.com;
  root /path;
  include snippets/wordpress.conf;
  auth_basic "Введите пароль.";
  auth_basic_user_file /etc/nginx/.htpasswd;
}

这是 curl 输出,看起来很漂亮,内容类型字符集为 utf-8:

$ curl -I http://example.com/
HTTP/1.1 401 Unauthorized
Date: Sat, 12 Dec 2015 08:37:41 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=x; expires=Sun, 11-Dec-16 08:37:41 GMT; path=/; domain=.mydomain.com; HttpOnly
WWW-Authenticate: Basic realm="Введите пароль."
Server: cloudflare-nginx
CF-RAY: xxxxxxxxxxxx-ARN

但这是 Chrome、Safari、Opera、Yandex 浏览器的输出...我能够尝试的每个浏览器:

To view this page, you must log in to this area on example.com:80: ÐведиÑе паÑолÑ.

您可以尝试使用引用可打印的文本

server {
  charset utf-8;
  listen 80;
  server_name example.com;
  root /path;
  include snippets/wordpress.conf;
  auth_basic "=?UTF-8?Q?=D0=92=D0=B2=D0=B5=D0=B4=D0=B8=D1=82=D0=B5=20=D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8C.?=";
  auth_basic_user_file /etc/nginx/.htpasswd;
}

为了完整起见:在一个关于 serverfault 的新问题中,我发现了这个 answer

RFC 7617 Section 3

The 'realm' parameter carries data that can be considered textual; however, `[RFC7235] does not define a way to reliably transport non- US-ASCII characters. This is a known issue that would need to be addressed in a revision to that specification.

realm 参数是您在 auth_basic 指令中输入的字符串。所以,不能提出任何建议,但坚持使用 ASCII。