国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 建站經(jīng)驗(yàn) > 正文

Nginx 配置反向代理使用 Google fonts 字體并開啟 HTTP2/SSL 支

2019-11-02 15:55:10
字體:
供稿:網(wǎng)友

由于博客主題使用了 Google fonts PT Serif 字體,國(guó)內(nèi)只能通過中科大的代理來使用 Google fonts 字體。然而最近發(fā)現(xiàn)其速度不穩(wěn)定,響應(yīng)時(shí)間有時(shí)候甚至超過 600ms。剛好因?yàn)樽约河?vultr 的 VPS(帶小尾巴) 就自己動(dòng)手搭了個(gè)來用

VPS 環(huán)境如下:

Ubuntu 14.04

Nginx 1.12.0 (最新版各別配置與之前不一樣)

Openssl 1.0.2j (新版 Nginx 開啟 http2 需要的最低 openssl 版本)

重新編譯安裝 Nginx

如果之前編譯安裝沒開啟相關(guān)模塊的話需要重新編譯,大概參數(shù)如下:

復(fù)制代碼 代碼如下:./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/ssl --with-http_v2_module --with-http_sub_module

編譯完沒有出錯(cuò)的話就 make && make install 就 OK 了

配置 Nginx 反代

基本配置

upstream google {  server fonts.googleapis.com:80;}upstream gstatic {  server fonts.gstatic.com:80;}proxy_temp_path  /your/path/tmp 1 2;proxy_cache_path /your/path/cache levels=1:2 keys_zone=cache1:100m inactive=30d max_size=1g;

80 端口配置

server {  listen 80;  server_name your.proxy.domain;  root /your/path/;  location /css {    sub_filter 'fonts.gstatic.com' 'your.proxy.domain';    sub_filter_once off;    sub_filter_types text/css;    proxy_pass_header Server;    proxy_set_header Host fonts.googleapis.com;    proxy_set_header Accept-Encoding '';    proxy_redirect off;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Scheme $scheme;    proxy_pass http://google;    proxy_cache cache1;    proxy_cache_key $host$uri$is_args$args;    proxy_cache_valid 200 304 10m;    expires 365d;  }  location / {    proxy_pass_header Server;    proxy_set_header Host fonts.gstatic.com;    proxy_redirect off;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Scheme $scheme;    proxy_pass http://gstatic;    proxy_cache cache1;    proxy_cache_key $host$uri$is_args$args;    proxy_cache_valid 200 304 10m;    expires 365d;  }}

443 端口配置

首先你得有個(gè)免費(fèi)的 HTTPS 證書,這個(gè)可以參考我之前的文章:免費(fèi) Https 證書(Let'S Encrypt)申請(qǐng)與配置

注意設(shè)置 sub_filter 字段的時(shí)候 你的域名要加上 https://,要不然會(huì)出現(xiàn)代理的 CSS 文件中的字體文件引用是 HTTP 而請(qǐng)求報(bào) blocked/mixed-content 錯(cuò)

server {  listen 443 ssl http2;  ssl on;  ssl_certificate /etc/letsencrypt/live/your.proxy.domain/fullchain.pem;  ssl_certificate_key /etc/letsencrypt/live/your.proxy.domain/privkey.pem;  ssl_dhparam /etc/ssl/certs/dhparams.pem;  ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;  ssl_ciphers HIGH:!aNULL:!MD5;  server_name your.proxy.domain;  root /var/sites/fonts/;  location /css {    sub_filter 'http://fonts.gstatic.com' 'https://your.proxy.domain';    sub_filter_once off;    sub_filter_types text/css;    proxy_pass_header Server;    proxy_set_header Host fonts.googleapis.com;    proxy_set_header Accept-Encoding '';    proxy_redirect off;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Scheme $scheme;    proxy_pass http://google;    proxy_cache cache1;    proxy_cache_key $host$uri$is_args$args;    proxy_cache_valid 200 304 10m;    expires 365d;  }  location / {    proxy_pass_header Server;    proxy_set_header Host fonts.gstatic.com;    proxy_redirect off;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Scheme $scheme;    proxy_pass http://gstatic;    proxy_cache cache1;    proxy_cache_key $host$uri$is_args$args;    proxy_cache_valid 200 304 10m;    expires 365d;  }}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 海兴县| 南汇区| 栾川县| 银川市| 洛隆县| 天祝| 股票| 馆陶县| 南宫市| 容城县| 读书| 稻城县| 西华县| 彰武县| 加查县| 启东市| 柯坪县| 凌源市| 济南市| 丹江口市| 栾川县| 枣庄市| 仁化县| 遂溪县| 庆云县| 美姑县| 昌乐县| 积石山| 自贡市| 安庆市| 沈阳市| 岚皋县| 桂东县| 稷山县| 科尔| 永康市| 钟祥市| 兰考县| 合肥市| 肥乡县| 新巴尔虎右旗|