首页 > 解决方案 > 如何在 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";
        }    
}

提前致谢!

标签: nginxmagento-1.9google-pagespeedexpires-header

解决方案


您可以尝试使用额外的反斜杠吗?

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 。

此致,


推荐阅读