IP カメラのリバース プロキシ

IP カメラのリバース プロキシ

私はストリームをレンダリングするために基本認証を必要とするAmcrestカメラを使用しています(ドキュメンテーション- 17 ページ)。カメラには からアクセスしますhttp://admin:password@IP_CAMERA/cgi-bin/mjpg/video.cgi

を押しようとすると:56700、ハードコードされているにもかかわらず認証を求められます (下記)。正しい資格情報を入力しても失敗します。何が間違っているのでしょうか?

    server {
        listen 56700;
        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://IP_CAMERA/cgi-bin/mjpg/video.cgi;
            proxy_set_header Authorization "Basic xxx";
        }
    }

proxy_pass_header Authorization;説明どおりに追加してみましたここ

答え1

上で述べたように、これは次のように解決できます。

proxy_set_header Authorization "Basic dXNlcjpwYXNzd29yZA==";

dXNlcjpwYXNzd29yZA==コマンドの結果は次のようになります:echo -n "user:password" | base64

すでに試してみたと思います

とにかく、正しい場所は次のようになると思います

location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://IP_CAMERA;
    proxy_set_header Authorization "Basic dXNlcjpwYXNzd29yZA==";
    proxy_set_header Authorization "Basic $http_authorization"; # For interactive mode
}

/cgi-bin/mjpg/video.cgiブラウザまたはHTTPクライアント側で渡されるため

またはもしそれがうまくいかないなら、それはこのケースに関連している可能性があります https://stackoverflow.com/questions/14839712/nginx-reverse-proxy-passthrough-basic-authenication

カメラにいくつかの領域チェックがある場合は、開発ツールのヘッダータブ - 応答ヘッダーセクションで予想される領域を確認できます。

ただし、nginxをコンパイルするにはheaders-more-nginx-module

このスクリプトで作れます

cd /usr/src
NGINXFILE=$(wget -qO- http://nginx.org/en/download.html | tr ' ' '\n' | egrep -o 'nginx.+?tar.gz' | head -1)
wget http://nginx.org/download/${NGINXFILE}
tar zxvf ${NGINXFILE}
cd ${NGINXFILE%.*.*}

cp -r /etc/nginx /root/nginx_$(date +%F) #Backup current nginx configs

cd /usr/src
git clone https://github.com/openresty/headers-more-nginx-module.git

./configure --add-module=/usr/src/headers-more-nginx-module --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
make
make install

完了したら、次のような設定を試すことができます:

location / {
  proxy_http_version      1.1;
  proxy_pass_request_headers on;
  proxy_set_header        Host            $host;
  proxy_set_header        X-Real-IP       $remote_addr;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

  more_set_input_headers  'Authorization: Basic dXNlcjpwYXNzd29yZA=='; 
  #more_set_input_headers  'Authorization: $http_authorization'; # For interactive mode
  proxy_set_header  Accept-Encoding  "";

  proxy_pass              http://IP_CAMERA;
  proxy_redirect          default;
  more_set_headers        -s 401 'www-authenticate: Basic realm="Authentication Required"';
}

www-authenticate: Basic realm="Authentication Required"このヘッダーの実際のデータは

両方のケースをチェックしましたが、私の場合はうまくいきました。カスタムフラスコアプリケーションでテストしました。残念ながら、個人的なデバッグ用にそのようなカメラを持っていません。

答え2

Amcrest固有のソリューションで編集

ある時点で(2017年頃?)Amcrestファームウェアアップデートをリリースしました基本認証を削除しましたIP カメラから認証ができなくなるため、ダイジェスト認証が唯一の選択肢となります。

このStack Overflowの回答FastCGI と nginx を使用して、必要に応じてダイジェスト認証を削除するには、これが最善の選択肢かもしれません。

あるいは、カメラのファームウェアをダウングレードして、再び基本認証をサポートする方法を見つけることもできます。


前の回答

ユーザー名とパスワードの間にコロンを入れて Base64 エンコードしていますか?

のためにHTTP 基本認証、次の操作を行う必要があります。

proxy_set_header Authorization "Basic xxx";

xxxを に置き換えますBase64(<username>:<password>)。つまり、Base-64 エンコーダーを見つけて、ユーザー名、リテラル コロン ( :) 文字、およびパスワードを入力し、 をxxx結果の文字列に置き換えます。

たとえば、ユーザー名がadmin、パスワードが の場合hunter2、Bash プロンプトで次のコマンドを実行できます。

printf %s 'admin:hunter2' | base64

結果の文字列を次のようにヘッダーに配置します。

proxy_set_header Authorization "Basic YWRtaW46aHVudGVyMg==";

答え3

当てずっぽう

ファイルのアクセス許可が正しく設定されていない場合、サインイン ボックスが表示されることがあります。このサインイン ボックスは、場合によっては、接続レベルではなくファイル アクセス許可レベル用です。これは、Web サーバー側で何らかのファイル アクセス許可の問題が発生している可能性があります。接続/サービスにファイル アクセス許可がない場合は、接続/サービス ベースの資格情報とファイル レベルの資格情報の 2 つの異なる資格情報が必要になることがあります。

関連情報