
헤더 필드 에 문제가 있습니다 expires
. 다음 nginx 규칙은 이 헤더를 제공합니다(만료 헤더 없음). 만료 헤더가 전달되지 않는 이유에 대한 아이디어가 있습니까?
헤더: /css/v1/afile.css
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 14 Sep 2013 07:29:59 GMT
Content-Type: text/css
Content-Length: 12548
Last-Modified: Sat, 11 May 2013 11:05:51 GMT
Connection: keep-alive
Accept-Ranges: bytes
Nginx 구성:
server {
listen 80 default_server;
server_name _;
root /var/www/apps/myapp/public/app/webroot;
index index.php index.html index.htm;
server_tokens off;
access_log /var/www/apps/myapp/logs/access.log;
error_log /var/www/apps/myapp/logs/error.log;
client_max_body_size 20M;
rewrite_log on;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ /(js|css)/v[0-9]+/(.*) {
access_log off;
expires 7d;
add_header Cache-Control public;
try_files $uri $uri/ /$1/$2;
}
# Pass the PHP scripts to FastCGI server
location ~ \.php$ {
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_intercept_errors on; # to support 404s for PHP files not found
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
답변1
동일한 위치 블록에 설정된 만료 헤더를 표시하려면 다음이 작동해야 합니다.
try_files $uri $uri/ /$1/$2 =404;
Nginx 위키에 따르면,try_filesURI 또는 상태 코드로 끝나야 합니다. 활성화하면 만료가 설정되지 않은 이유에 대한 자세한 정보를 얻을 수 있습니다.Nginx에서 디버깅.
업데이트:
만료 헤더가 전달되지 않는 이유에 대한 아이디어가 있습니까?
이 흥미로운 상황을 파악하기 위해 디버깅을 활성화했습니다. 이것이 내가 찾은 것입니다 ...
다음은 이전에 링크된 try_files 위키 기사에서 직접 인용한 내용입니다...
파일이 발견되지 않으면 마지막 매개변수에 지정된 URI로 내부 리디렉션이 수행됩니다.
따라서 다음 코드를 사용하면 ...
try_files $uri $uri/ /$1/$2;
nginx가 찾을 수 없으며 $uri
( $uri/
귀하의 경우 /css/v1/afile.css 및 /css/v1/afile.css/) 마지막 매개변수에 지정된 URI에 대한 내부 리디렉션이 이루어집니다. 따라서 내부 리디렉션 후 위치가 /$1/$2
발견됩니다(귀하의 경우 /css/afile.css).다른 위치 블록에. 만료일이 없는 다른 위치 블록에 의해 실행되므로 만료가 표시되지 않습니다.