저는 스트림을 렌더링하기 위해 기본 인증이 필요한 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펌웨어 업데이트를 출시했습니다.기본 인증이 제거되었습니다.다이제스트 인증만 유일한 옵션으로 남겨둡니다.
이 스택 오버플로 답변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
어둠 속에서 촬영
때로는 파일 권한이 올바르게 설정되지 않은 경우 연결 수준이 아닌 파일 권한 수준에 대한 로그인 상자가 표시될 수 있다는 것을 알고 있습니다. 아마도 웹 서버 측에서 일종의 파일 권한 문제가 발생하고 있는 것일까요? 연결/서비스 기반 자격 증명과 연결/서비스에 파일 권한이 없는 경우 파일 수준 자격 증명의 두 가지 다른 자격 증명으로 끝날 수 있습니다.