安装Nginx
安装Nginx,设置开机自启
sudo apt update && sudo apt install nginx -ysudo systemctl enable nginx设置Nginx代理
新增图片代理规则,代理到 http://mysite.com/img/ 路径下
sudo vim /etc/nginx/sites-available/defaultlocation ~* ^/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 -tsudo nginx -s reload其他问题
- 注意监听使用的端口和匹配的域名
listen 80;
server_name _;