httphttps_0">从http切换至https
许多不同ip的图片地址需要统一进行代理
部分图片地址是重定向地址
nginx_4">nginx配置
主站地址:https://192.168.123.100/
- 主站nginx配置
server {listen 443 ssl;server_name localhost;#ssl证书ssl_certificate ../ssl/ca.crt; #私钥文件ssl_certificate_key ../ssl/ca.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m;ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}location /proxyAgent {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 X-Forwarded-Proto $scheme;proxy_intercept_errors on;if ($args ~* "imgUrl=(.*)") {proxy_pass $1;error_page 301 302 = @handle_redirect;}}location @handle_redirect {set $saved_redirect_location $upstream_http_location;rewrite ^(.*)$ $saved_redirect_location break;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 X-Forwarded-Proto $scheme;proxy_pass $saved_redirect_location;}
}
- 主站html
<img src="/proxyAgent/?imgUrl=http://192.168.123.102:8093/test/123456?url=1234567&type=picpic">
<img src="/proxyAgent/?imgUrl=http://192.168.123.102/test/1.jpg">
<img src="/proxyAgent/?imgUrl=https://192.168.123.105/3.jpg">
- 192.168.123.102:8093为java模拟重定向
@GetMapping("/{picId}")public void getPic(@PathVariable("picId") String picId,@RequestParam("url") String url,@RequestParam(value = "type") String type, HttpServletResponse response) throws IOException {if (StrUtil.isBlank(type)) {return;}if (StrUtil.isBlank(url)) {return;}System.out.println(type);System.out.println(url);response.sendRedirect("http://192.168.123.102/test/2.jpg");}
最终三张图片均可正常访问
https://i-blog.csdnimg.cn/direct/ba720af866964a76b14aef22cb47ac98.png" alt="在这里插入图片描述" />