2016-10-22 13 views
0

CentOSでnginxを実行しています。6.ドメインはsslを使用するように設定されています。特定のフォルダにはパスワードで保護する必要があります。私がhttpでurlをタイプすると、ブラウザは基本的にユーザを入力して渡します。 httpsで同じURLを入力すると、特定のフォルダのインデックスファイルが表示され、ユーザーパスは要求されません。Nginxの基本認証はhttpで動作しますが、httpsでは動作しません

私は私のドメイン固有nginx.confファイルでこれを持っている:

location /protected_folder { 
     auth_basic "Restricted"; 
     auth_basic_user_file /etc/nginx/.htpasswd; 
    } 

がどのように使用したURLの両方がHTTPとHTTPSのパスワードで保護されていることを確認することができますか?

答えて

1

nginxには、nxingx.confとsnginx.confという同じディレクトリに2つの設定ファイルがあります。私は単純にsnginx.confを同じauthルールで更新しなければならず、すべてがうまくいきました。

1

あなたは80と443ポートにあなたの制限されたコンフィギュレーションを配置する必要があります。

の/ etc/nginxの/サイト利用可能/

server 
{ 
    listen    80; 
    server_name   YOUR.FQDN; 

.....other config of vhost..... 

    location /protected_folder { 
     auth_basic "Restricted"; 
     auth_basic_user_file /etc/nginx/.htpasswd; 
    } 
} 

server 
{ 
    listen    443; 
    server_name   YOUR.FQDN; 

.....other config of vhost..... 

    location /protected_folder { 
     auth_basic "Restricted"; 
     auth_basic_user_file /etc/nginx/.htpasswd; 
    } 
} 

か、httpをhttpsに要求をリダイレクトすることができMY_VHOST:

server 
{ 
     listen    80; 
     server_name   YOUR.FQDN; 
     return 301   https://YOUR.FQDN$request_uri; 

} 
server 
{ 
    listen    443; 
    server_name   YOUR.FQDN; 

.....other config of vhost..... 

    location /protected_folder { 
     auth_basic "Restricted"; 
     auth_basic_user_file /etc/nginx/.htpasswd; 
    } 
} 
関連する問題