nginx - 如何在 nginx 中添加过期标头?
问题描述
我们在 /etc/nginx/site-available/default 中添加了过期标头,但没有反映在 gtmatrix/google 速度中,我们还检查了 curl 网站。
请检查我们下面的代码,
server {
root /var/www/html;
location / {
index index.php index.html;
try_files $uri $uri/ @handler;
}
location /. {
return 404;
}
location @handler {
rewrite / /index.php;
}
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
if (!-e $request_filename) {
rewrite / /index.php last;
}
include snippets/fastcgi-php.conf;
# With php7.0-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_read_timeout 20000;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_param PHP_VALUE "memory_limit = -1";
}
location ~* .(js|jpg|jpeg|gif|png|css|tgz|gz|rar|bz2|doc|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|woff|woff2|svg)$ {
expires 30d;
add_header Pragma "public";
add_header Cache-Control "public";
}
}
提前致谢!
解决方案
您可以尝试使用额外的反斜杠吗?
location ~* \.(js|jpg|jpeg|gif|png|css|tgz|gz|rar|bz2|doc|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|woff|woff2|svg)$ {
expires 30d;
add_header Pragma "public";
add_header Cache-Control "public";
}
此外,您可能希望拆分块以便在有意义时使用gzip off 。
此致,
推荐阅读
- ruby-on-rails - Rails activeadmin 导出 PDF
- git - 当我克隆按钮单击时括号 Git 错误
- reporting-services - web.config 中的 Vuejs 和 SSRS 报告连接
- python - 性能 - 在 Python 中比较 2 个大型字符串列表的最快方法
- javascript - 在常规 html 页面中使用 vue-multiselect.js
- wordpress - 如果 WordPress 类别为空,如何显示一行文本?
- r - order 函数如何打破 R 中的关系?
- xamarin.forms - Xamarin 跨平台蓝牙连接示例代码
- ruby - OpenSSL::X509::CertificateError:嵌套 asn1 错误
- angularjs - 使用Springboot从angularjs上传图像到FTP