avatar🐀
霂枯木霂枯木的小站

To witness the sunrise and the sea of blossoms.

行可兼知,而知不可兼行

Nginx代理加速图片

安装Nginx ​

安装Nginx,设置开机自启

sudo apt update && sudo apt install nginx -y
sudo systemctl enable nginx

设置Nginx代理 ​

新增图片代理规则,代理到 http://mysite.com/img/ 路径下

sudo vim /etc/nginx/sites-available/default
location ~* ^/img/(.*)$ {
    # 使用 HTTPS 回源
    proxy_pass https://i.imgur.com/$1$is_args$args;
    
    # 关键:伪装 Host
    proxy_set_header Host i.imgur.com;
    
    # 【核心修复】添加防盗链欺骗头,告诉 Imgur 请求来自本站内部
    proxy_set_header Referer "https://imgur.com/";
    proxy_set_header Origin "https://imgur.com";
    
    # 伪装浏览器
    proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
    
    # 【必须保留】关闭 SSL 验证(绕过国内 SNI 阻断)
    proxy_ssl_verify off;
    proxy_ssl_server_name on;
        
    # 超时设置
    proxy_connect_timeout 30s;
    proxy_read_timeout 30s;
}

检查语法并重启 ​

检查语法并重启

sudo nginx -t
sudo nginx -s reload

其他问题 ​

  1. 注意监听使用的端口和匹配的域名
listen 80;
server_name _;
服务器基础安全配置
PM2的基本使用
由 Valaxy v1.2.0 驱动|主题-Yunv1.2.0