新的 Blog 是基于 Hugo 搭建的,原始博客内容和生成的静态资源,都是托管在 Github 仓库里面的。但 Github Pages 有时候会抽风,并且访问速度并不是很稳定,因此萌生了使用 NGINX 反向代理 Github Pages 的想法。
基本原理就是将目标站点(Github Pages) 作为一个 upstream 服务,然后 NGINX 负责将所有流量都转发到 upstream 即可。因此,我们的配置文件编写就比较简单了,只需要注意 Host 等信息需要使用 upstream 站点的信息(Github Pages)。
blog-proxy.conf
server{
listen 80;
server_name your.blog.com;
return 301 https://your.blog.com$request_uri;
}
server{
listen 443 ssl http2;
server_name your.blog.com;
ssl_certificate /opt/cert/sslfile.pem;
ssl_certificate_key /opt/cert/sslfile.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_redirect off;
proxy_set_header Host yourblog.github.io; # 填写 Github Pages 的地址。
proxy_set_header X-Host yourblog.github.io; # 填写 Github Pages 的地址。
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Cache pages.
proxy_cache_valid 200 206 304 301 302 1d; # 配置缓存过期时间。
proxy_cache_valid any 1d;
proxy_cache_key $uri;
proxy_pass https://yourblog.github.io; # 填写 Github Pages 的地址。
}
}
参考文章:https://real-zony.github.io/p/forward-github-pages-site-with-nginx/
声明:本文采用 BY-NC-SA 协议进行授权,如无注明均为原创,转载请注明转自 你好!刘
本文地址:使用 NGINX 反向代理 Github Pages 站点
本文地址:使用 NGINX 反向代理 Github Pages 站点
发表评论