nginx反向代理解决googleapis字体库问题

虽然有第三方的,但是自己nginx里面写死配置来得安稳些.

sub_filter_once off;
sub_filter_types text/css;
sub_filter "//fonts.googleapis.com" "/assets/vendor/googleapis";
sub_filter "https://fonts.googleapis.com" "/assets/vendor/googleapis";

location /assets/vendor/googleapis {
  rewrite ^/assets/vendor/googleapis/(.+)$ /$1 break;
  proxy_pass https://fonts.googleapis.com;
  proxy_set_header Host "fonts.googleapis.com";
  proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0";
  expires 1d;
  sub_filter_once off;
  sub_filter_types text/css;
  sub_filter "https://fonts.gstatic.com" "/assets/vendor/gstatic";
}

location /assets/vendor/gstatic {
  rewrite ^/assets/vendor/gstatic/(.+)$ /$1 break;
  proxy_pass https://fonts.gstatic.com:443;
  proxy_set_header Host "fonts.gstatic.com";
  expires 1y;
}

添加新评论 »