
특정 디렉토리( )에 대해 basic_auth를 비활성화하려고 /api/
하지만 작업 중인 사이트의 나머지 부분에 대해서는 여전히 기본 인증이 있습니다. 다음은 내 것입니다 nginx.conf
:
server {
# base settings
listen 80;
server_name somesite-somewhere-anywhere.com;
root /var/www/wordpress;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
# setup logs
access_log /var/log/nginx/somesite-somewhere-anywhere.com.access.log;
error_log /var/log/nginx/somesite-somewhere-anywhere.com.error.log;
# setup 404
error_page 404 /404.html;
location /404.html {
internal;
}
# map 403 to 404
error_page 403 = 404;
# hide wordpress details
location ~ /(\.|wp-config.php|readme.html|licence.txt) {
return 404;
}
# add trailing slash to wp-admin requests
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# ignore robots in logging
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# ssl redirect
# setup location
location / {
# setup basic auth
auth_basic dk;
auth_basic_user_file /var/www/htpasswd;
# fastcgi setup
location ~* (^(?!(?:(?!(php|inc)).)*/uploads/).*?(php)) {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_pass unix:/var/run/php-fpm.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
# prevent access to hidden files
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}
# allow access to api without auth
location /api/ {
auth_basic "off" ;
}
}
답변1
에서 볼 수 있습니다nginx 인증 기본 문서"auth_basic 꺼짐;" 당신이 필요로하는 것입니다. 그래서 나는 여기에 뭔가 다른 일이 벌어지고 있다고 의심합니다. URL을 어떻게 입력하고 있는지 보여주세요.
아마도 후행 슬래시 없이 /api를 치고 있습니까? 여전히 문제가 있는 경우 다음을 사용하여 문제를 해결할 수 있습니다.
location /api/ {
satisfy any;
allow all;
auth_basic "dk";
auth_basic_user_file "/var/www/htpasswd";
}
잘못된 방법이지만 환경에서 올바른 일을 수행하는 것의 중요성에 따라 신속할 수도 있습니다(위치/상속이 올바르게 지정된 경우).