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

首頁(yè) > 網(wǎng)站 > Nginx > 正文

Nginx 配置反向代理使用 Google fonts 字體并開(kāi)啟 HTTP2/SSL 支持

2024-08-30 12:28:49
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

VPS 環(huán)境如下:

Ubuntu 14.04
Nginx 1.12.0 (最新版各別配置與之前不一樣)
Openssl 1.0.2j (新版 Nginx 開(kāi)啟 http2 需要的最低 openssl 版本)

重新編譯安裝 Nginx

如果之前編譯安裝沒(méi)開(kāi)啟相關(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

 

編譯完沒(méi)有出錯(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 證書(shū),這個(gè)可以參考我之前的文章:免費(fèi) Https 證書(shū)(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;  }}

安全防盜鏈

如果不共享給其它人用的話還需要在配置中加入 referer 白名單判斷,不符合條件的將返回 403

valid_referers server_name *.your.domain.com *.other.domain.com;if ($invalid_referer) {  return 403;}

上面就是本文的全部?jī)?nèi)容了,希望對(duì)大家學(xué)習(xí)配置nginx反向代理以及支持SSL有所幫助


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 阿图什市| 孟村| 晴隆县| 合山市| 依兰县| 高要市| 汝南县| 南皮县| 枣强县| 平谷区| 临邑县| 富民县| 册亨县| 武夷山市| 南昌市| 富裕县| 镇安县| 澜沧| 江西省| 琼结县| 莱阳市| 灵台县| 揭西县| 芦溪县| 田东县| 南木林县| 当涂县| 大方县| 古浪县| 桐城市| 栾川县| 洛阳市| 磐石市| 津南区| 潼关县| 禄劝| 太原市| 樟树市| 青神县| 赤城县| 朔州市|