文章前言:
我弄了这么久才发现 反向代理之后 防盗链配置会失效
这就很尴尬
教程+修复:
这里只演示宝塔的教程
首先进入反向代理的站点配置文件目录
可以在站点配置文件中找到 默认目录为/www/server/panel/vhost/nginx/proxy/站点域名/
打开需要修改的配置文件 将以下代码:
location / { proxy_pass https://你的反代IP; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache add_header Cache-Control no-cache; expires 12h; }
修改为
location / { location ~ .*.(jpg|jpeg|gif|png|js|css)$ { expires 30d; access_log /dev/null; valid_referers 防盗链域名; if ($invalid_referer){ return 403; } proxy_pass https://你的反代IP; } location / { proxy_pass https://你的反代IP; } proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache add_header Cache-Control no-cache; expires 12h; }
© 版权声明
内容转载于网络,请读者自行鉴别
THE END