2016-09-06 3 views
2

모든 폴더에서 다음과 동일한 설정을 유지하고 싶습니다. 폴더/wp-admin에서 add_header Cache-Control "no-store"; 설정은 .php 파일의 경우 만 추가해야합니다.Nginx를 사용하여 단일 폴더에 특정 헤더를 설정하는 방법은 무엇입니까?

질문 :
Nginx의 특정 폴더에서만 설정을 변경하는 방법은 무엇입니까?

location ~ \.php$ { 
    try_files $uri =404; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
    fastcgi_index index.php; 
    include fastcgi.conf; 
    add_header Cache-Control "public"; 
    access_log off; 
} 

location [IF PHP FILE IN wp-admin FOLDER] { 
    add_header Cache-Control "no-store"; 
} 

location ~* \.(js|css|svg|png|jpg|jpeg|gif|ico|eot|otf|ttf|woff)$ { 
    add_header Access-Control-Allow-Origin *; 
    add_header Cache-Control "public"; 
    access_log off; 
    log_not_found off; 
    expires 1y; 
} 

답변

1

PHP 파일을 처리하는 위치 블록은 모든 fastcgi 매개 변수와 지시문을 포함해야합니다. 요청 처리에 대해서는 this document을 참조하십시오.

아직 테스트하지 않았지만 map 지시문을 사용하여 add_header 문에 적절한 값을 선택할 수 있어야합니다. 예를 들어

:

map $request_uri $cc { 
    ~^/wp-admin "no-store"; 
    default  "public"; 
} 

server { 
    ... 
    location ~ \.php$ { 
     add_header Cache-Control $cc; 
     ... 
    } 
} 

은 자세한 내용은 this document를 참조하십시오.

+0

신난다, 고마워. –

관련 문제