如何在 google 页面见解中获得好成绩 Nginx 和 Apache

How to get good scores in google page insights Nginx & Apache

我正在对我的网站进行性能优化,但是很难匹配 google 的所有建议,因为大多数建议都是基于 nginx 中的服务器端,因为 .htaccess 将无法工作nginx.

请在 nginx 和 apache 方面指导我,以便我可以优化我的网站。

以下是我实施的步骤。

Apache

  1. Mod_expires
  2. Mod_headers
  3. 启用压缩
  4. 利用浏览器缓存

参考 Link : Leverage browser caching, how on apache or .htaccess?

Nginx

我没有在博客上找到任何评论信息。

请告诉我优化网站

您可以为不时更改的静态文件启用浏览器缓存。这是 nginx 的一些示例:

# Feed
location ~* \.(?:rss|atom)$ {
  expires 1h;
  add_header Cache-Control "public";
}

# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
  expires 1M;
  access_log off;
  add_header Cache-Control "public";
}

# CSS and Javascript
location ~* \.(?:css|js)$ {
  expires 1y;
  access_log off;
  add_header Cache-Control "public";
}

一些解释:

您需要使用 location 指令来利用浏览器缓存并提及您要缓存的特定类型的文件。

expires - 设置缓存时间。 add_header - 添加缓存 header 到浏览器。

您还可以通过添加以下内容为您的服务器启用 gzip 压缩: gzip on;