当前位置: 首页 > news >正文

使用nginx搭建通用的图片代理服务器,支持http/https/重定向式图片地址

从http切换至https

许多不同ip的图片地址需要统一进行代理
部分图片地址是重定向地址

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");}

最终三张图片均可正常访问

在这里插入图片描述

http://www.lryc.cn/news/522708.html

相关文章:

  • 零基础构建最简单的 Tauri2.0 桌面项目 Star 88.4k!!!
  • 智能科技与共情能力加持,哈曼重新定义驾乘体验
  • 猫贫血吃什么能快速补血?
  • 微服务拆分
  • Android SystemUI——车载CarSystemUI加载(八)
  • 2025年编程语言热度分析:Python领跑,Go与Rust崛起
  • 前缀和 (一维 二维)
  • 精选算法合集
  • HackMyVM-Klim靶机的测试报告
  • C++内存分布
  • mysql主从复制sql进程中断,报错Tablespace is missing for table ……
  • STM32 FreeRTOS 信号量
  • Codemirror6个人使用心得总结
  • Ruby语言的软件开发工具
  • OpenHarmony API 设计规范
  • ESP8266 AP模式 网页配网 arduino ide
  • OpenCV基础:获取子矩阵的几种方式
  • C++ 之多线程相关总结
  • EF Core全局查询筛选器
  • 【开源免费】基于SpringBoot+Vue.JS欢迪迈手机商城(JAVA毕业设计)
  • Objective-C语言的数据库交互
  • 基于 Spring Boot 和 Vue.js 的全栈购物平台开发实践
  • 笔记(数据运营方向)
  • qt vs ios开发应用环境搭建和上架商店的记录
  • [cg] glDrawBuffers MRT的应用
  • IO模型与NIO基础二
  • 【设计模式】 单例模式(单例模式哪几种实现,如何保证线程安全,反射破坏单例模式)
  • T-SQL语言的数据库交互
  • 【Linux系统】Ext系列磁盘文件系统二:引入文件系统(续篇)
  • 慧集通(DataLinkX)iPaaS集成平台-业务建模之域