%EC%97%90%20%EB%8C%80%ED%95%9C%20%EC%9D%B8%EC%A6%9D%EC%9D%84%20%EB%B9%84%ED%99%9C%EC%84%B1%ED%99%94%ED%95%A9%EB%8B%88%EB%8B%A4..png)
내 문제는 여기에 설명된 것과 정확히 동일합니다.HTTP OPTIONS 메서드에 대한 인증 비활성화(실행 전 요청). CORS와 HTTP 비밀번호를 동시에 사용하려고 합니다. 브라우저에 반송된 OPTIONS(상태 코드 401)가 표시되면 어떤 이유로든 즉시 CORS 헤더(없음)를 확인하고 요청을 거부합니다.
내 구성은 다음과 같습니다.
location /api/ {
proxy_pass http://127.0.0.1:14000;
proxy_set_header Host $host;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Headers "Authorization, Content-Type";
add_header Access-Control-Allow-Credentials true;
auth_basic "Restricted Area";
auth_basic_user_file /var/www/admin.htpasswd;
}
답변1
제가 생각해낸 해결책은 다음과 같습니다. 하지만 모든 CORS add_header 지시어 복제는 해결됩니다.
location /api/ {
proxy_pass http://127.0.0.1:14000;
proxy_set_header Host $host;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Headers "Authorization, Content-Type";
add_header Access-Control-Allow-Credentials true;
if ($request_method = OPTIONS) {
add_header Content-Length 0;
add_header Content-Type text/plain;
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
add_header Access-Control-Allow-Origin $http_origin;
add_header Access-Control-Allow-Headers "Authorization, Content-Type";
add_header Access-Control-Allow-Credentials true;
return 200;
}
auth_basic "Restricted Area";
auth_basic_user_file /var/www/admin.htpasswd;
}
답변2
노드가 요청을 관리할 수 있는 더 깔끔한 솔루션을 찾았습니다.
"location" 안에 다음 구성을 넣고 서버에서 auth_basic을 제거하세요. 이것은 작동합니다.
location / {
# Your node proxy configuration for example #
# Make options requests work #
limit_except OPTIONS {
auth_basic "Restricted access zone";
auth_basic_user_file /etc/nginx/pass/protected;
}
}
답변3
다음 정보는Limit_Exception/if 블록 문제, 다음을 사용하는 것이 좋습니다 map
.
map $request_method $auth_basic_value {
default "Restricted";
"OPTIONS" "off";
}
location / {
auth_basic $auth_basic_value;
}
해당 위치에 쿼리가 있으면 try_files
다른 위치에 쿼리를 다시 작성할 수 있으므로 를 설정해야 할 수도 있습니다 auth_basic $auth_basic_value
.