我有一个简单的要求,即向max-age
除主页之外的所有页面添加标题。
location ~* ^/(.+)$ {
add_header Cache-Control "public, max-age=86400";
}
这个正则表达式应该可以工作,但是 Nginx 忽略了:
$ echo "/blog/pos1" | egrep "^/(.+)$" && echo "MATCH" || echo "NO MATCH"
/blog/pos1
MATCH
$ echo "/" | egrep "^/(.+)$" && echo "MATCH" || echo "NO MATCH"
NO MATCH
$ echo "" | egrep "^/(.+)$" && echo "MATCH" || echo "NO MATCH"
NO MATCH
配置:
server {
listen 80;
root /var/www/html/test;
index index.php index.html index.htm;
server_name tmp.local;
location = /favicon.ico {
return 204;
}
location ~ ^/. {
expires 86400s;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
location ~* \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|flv|mp3)$ {
access_log off;
log_not_found off;
expires 1209600s;
add_header X-Frame-Options "DENY";
}
}