2016-12-03 27 views
2

我已阅读此post Nginx不支持多个授权标头。如何检查请求标头中是否包含nginx的授权

我想知道,如果 授权标头存在,我将如何检查http请求。

基本上我在我的网页上添加了一个基本的认证,因为它还没有准备好生产。我的网站是一个单页面应用程序,我已经在索引页面中成功添加了认证,但我的网站也有登录功能。当我登录时,它不断要求重新进行身份验证。进出口新的nginx的,我不太清楚如何与解决这个

location/{ 

     root /path/to/my/app/root/folder; 
     index index.html index.php; 

     #I want to only executed these lines only on the index page and login page 
     auth_basic "Restricted"; 
     auth_basic_user_file /etc/nginx/.htpasswd; 
    } 

回答

0

您可以使用curl看标题:

$ curl -v -u your_user_name "http://......." 

外观为> Authorization: Basic ...线,包含Base64编码user:pass

可以使用解码字符串:

printf auth_string | base64 --decode 

更多细节here


此外,确保/etc/nginx/.htpasswd有正确的权限为nginx能够读取它,它包含了您的用户名/密码凭证由nginxinfo here)识别的格式:

1。纯文本:

# comment 
    name1:password1 
    name2:password2:comment 
    name3:password3 

2.加密/散列:

  • 加密与隐窝()函数;可以使用Apache HTTP Server发行版中的“htpasswd”实用程序或“openssl passwd”命令生成。

  • 与基于MD5的密码算法(apr1)的Apache变体进行哈希处理;可以使用相同的工具生成;

  • 由“{scheme} data”语法(1.0.3+)指定,如RFC 2307中所述;目前实施的方案包括PLAIN(不应使用示例1,不应该使用),SHA(1.3.13)(不应使用SHA-1 哈希)和SSHA(盐腌SHA-1哈希,通过某些软件使用 包,特别是OpenLDAP和Dovecot)。

$ htpasswd 
Usage: 
    htpasswd [-cimBdpsDv] [-C cost] passwordfile username 
    htpasswd -b[cmBdpsDv] [-C cost] passwordfile username password 

    htpasswd -n[imBdps] [-C cost] username 
    htpasswd -nb[mBdps] [-C cost] username password 
-c Create a new file. 
-n Don't update file; display results on stdout. 
-b Use the password from the command line rather than prompting for it. 
-i Read password from stdin without verification (for script usage). 
-m Force MD5 encryption of the password (default). 
-B Force bcrypt encryption of the password (very secure). 
-C Set the computing time used for the bcrypt algorithm 
    (higher is more secure but slower, default: 5, valid: 4 to 31). 
-d Force CRYPT encryption of the password (8 chars max, insecure). 
-s Force SHA encryption of the password (insecure). 
-p Do not encrypt the password (plaintext, insecure). 
-D Delete the specified user. 
-v Verify password for the specified user. 
On other systems than Windows and NetWare the '-p' flag will probably not work. 
The SHA algorithm does not use a salt and is less secure than the MD5 algorithm. 
相关问题