0

관리자 컨트롤러를 auth_basic 인증하에 사용하려고합니다.

  • /index.php?r= : 내가 요청이 예를 들어 인수 r에서 '관리'를 포함 할 때 인증 메시지를 표시 할 필요가

    location /index.php { 
        if ($arg_r ~ admin) { 
         auth_basic       "Restricted"; 
         auth_basic_user_file    /etc/nginx/mywebsite/.htpasswd; 
        } 
    } 
    
    location ~ \.php$ { 
        include fastcgi_params; 
        fastcgi_index index.php; 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
        fastcgi_param PATH_INFO $fastcgi_script_name; 
        fastcgi_pass php; 
    } 
    

    :이처럼 내의 nginx의 설정이 모습입니다 관리자 -> 인증

  • /index.php?r=admin/anythinghere -> 인증
  • /index.php?r=site/index -> 아니요 인증

하지만 일하지 않고, 내가 뭘 잘못하고 있니?

답변

0

설명서에 따르면 "if"에는 auth_ *를 사용할 수 없습니다. 어쩌면 이것은 트릭을 수행 할 수 있습니다.

location = /index.php { 
    if ($arg_r ~ admin) { 
     rewrite^/_admin/index.php$is_args$args last; 
    } 
    include fastcgi_params; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param PATH_INFO $fastcgi_script_name; 
    fastcgi_pass php; 
} 

location /_admin/index.php { 
    internal; 
    auth_basic       "Restricted"; 
    auth_basic_user_file    /etc/nginx/mywebsite/.htpasswd; 
    include fastcgi_params; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param PATH_INFO $fastcgi_script_name; 
    fastcgi_pass php; 
} 
location ~ \.php$ { 
    include fastcgi_params; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param PATH_INFO $fastcgi_script_name; 
    fastcgi_pass php; 
} 

인증이 설정된 중복 된 위치. "내부"지시문은이 위치로 직접 요청을 제한합니다. 그리고 첫 번째 위치에 "="를 추가 했으므로 /index.phpadasdasdsdfadsf를 /_auth/index.php에 다시 작성하는 것을 피할 수 있습니다.

+0

음, 내 구성을 정정하면 /index.php로 이동합니다. "Download"라는 이름으로 index.php를 다운로드 받지만, index.php? r = admin에서 auth를 요청합니다. 무엇 f ** k? – marioshki

+0

그의 의견 대신, ".php"파일은 파일 일뿐 아니라 PHP 처리에 사용하는 메커니즘 (예 : fastcgi 또는 proxy)을 포함시켜야합니다. –

+0

위치의 ~ \ .php가 설정 끝 부분에 있습니다. – marioshki