2016-12-03 7 views
2

このpostで、Nginxが複数の承認ヘッダをサポートしていないことが判明しました。リクエストヘッダにnginxの認証が含まれているかどうかを確認する方法

承認ヘッダーが存在する場合、httpリクエストをチェックインする方法が不思議でした。

基本的に私は自分のウェブページに基本認証を追加しています。私のサイトは単一のページアプリケーションであり、インデックスページに認証を追加しましたが、私のサイトもログイン機能を持っています。私がログインすると、認証を再度要求し続けます。イムnginxのために新しいと私はあなたがヘッダを参照してくださいcurlを使用することができ、この

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

で周りを取得する方法が非常に確認していない:のBase64エンコーディングが含まれてい> Authorization: Basic ...行の

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

ルックuser:pass

あなたは使用して文字列をデコードすることができます。

printf auth_string | base64 --decode 

詳細here

1:


また、必ず/etc/nginx/.htpasswdはそれを読むことができるようにnginxのための右の権限を持っており、それはあなたのユーザーが含まれていること/ nginxinfo here)で認識される形式で資格情報を渡します。プレーンテキスト:

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

2.暗号化/ハッシュは:

  • は陰窩()関数を用いて暗号化されました。 Apache HTTP Serverディストリビューションの "htpasswd"ユーティリティ、または
    "openssl passwd"コマンドを使用して生成できます。

  • MD5ベースのパスワードアルゴリズム(apr1)のApacheバリアントでハッシュ化されています。同じツールで生成することができます。

  • RFC 2307に記載されている "{scheme} data"構文(1.0.3+)で指定します。現在実装されているスキームには、PLAIN( の例、使用しないでください)、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. 
関連する問題