由于无法在Nginx中进行摘要认证,所以我尝试从源代码编译了一下
你不能进行Digest认证吗?
如果觉得基本验证有点问题,想要使用摘要验证的话,标准模块貌似不支持呢。从大约2012年的话题到现在,一直都没有提供支持。所以,即使现在(2015年5月),好像要使用由samizdatco先生制作的nginx-http-auth-digest这个第三方模块。
HttpAuthDigestModule (Nginx Wiki) – Nginx摘要认证模块 (GitHub)
基本认证不太好的。
基本身份验证意味着请求头的认证部分没有加密。在Chrome的开发者工具中查看请求头部分,可以看到下面的部分,将其转化为代码后…哇!
授权:基本 ZG9nOmRvZ2RvZw==
# echo "ZG9nOmRvZ2RvZw==" | base64 -d
dog:dogdog
我可以看到。所以应该使用摘要认证。
但是我不知道认证可以使用多种加密方式。
CRYPT , MD5 : Nginx 初版 から 対応
apr1 , PLAIN , SSHA : Nginx 1.0.3 から 対応
SHA : Nginx 1.3.13 から 対応
要在Nginx中进行基本身份验证(要求用户名和密码),可以这样做。
下载和编译Digest认证源代码。
好像这个 http-auth-digest-module 有个bug,所以samizdatco先生没有合并,所以(不知道为什么重复两次w)我也会同时应用补丁。
[FreeBSD][nginx] http-auth-digest模块补丁
我将使用以前在 Nginx 上构建 WebDAV 环境时遇到 PROPFIND 405 无法使用的源代码编译环境。
$ cd nginx-1.9.0
$ git clone https://github.com/samizdatco/nginx-http-auth-digest.git
$ cd nginx-http-auth-digest
$ git clone https://gist.github.com/frah/3921741
$ patch -u < 3921741/patch-ngx_http_auth_digest_module.diff
并且
$ ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --add-module=./nginx-dav-ext-module --add-module=./nginx-http-auth-digest
$ make
$ sudo make install
设置Digest认证
使用Apache附带的htdigest命令,但是如果执行yum install httpd-tools命令,只会安装命令,所以先安装好。
我们会创建一个Digest认证文件,用户为hage,密码为hagehage。
哦,另外realm名称我暂时先设为”digest realm-name”。
$ cd /etc/nginx
$ htdigest -c .htdigest 'digest realm-name' hage
好的。完成了。接下来要如何定义 Nginx?
location / {
# digest認証
auth_digest "digest realm-name";
auth_digest_user_file /etc/nginx/.htdigest;
重新启动 Nginx 并尝试访问。
顺便说一下,根据基本身份验证的设置方法。
因为在这边也要使用Apache附带的htpasswd命令,所以请先安装yum install httpd-tools。
我们将创建一个基本认证文件,用户名为hage,密码为hagehage。
$ cd /etc/nginx
$ sudo htpasswd -c .htpasswd hage
好的。完成了。接下来,Nginx的定义应该如何进行?
location / {
# basic認証
auth_basic "Aurh Basic";
auth_basic_user_file /etc/nginx/.htpasswd;