2025年3月22日 星期六 甲辰(龙)年 月廿一 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 服务器 > Nginx

通过ECS中Nginx反向代理到阿里云OSS内网,浏览器直接显示图片和文本

时间:05-21来源:作者:点击数:22

公司以前是自建MinIO文件服务,后面决定全部上云使用阿里云oss。出于一下几个目的决定使用nginx反向代理到阿里云oss。

1、前端发布app会有一个过度阶段,如果换成阿里云的oss地址,则有些用户还在使用MinIo的地址,会发生图片不在的情况。决定不更换前端地址。

2、阿里云OSS的收费包括存储、请求次数、外网流量地址。使用反向代理走内网可以规避外网流量。

nginx配置如下:

  • server {
  • listen 80 default_server;
  • listen [::]:80 default_server;
  • listen 443 ssl http2;
  • listen [::]:443 ssl http2;
  • server_name apptest.xxx.com;
  • root /usr/share/nginx/html;
  • ssl_certificate "/etc/nginx/ssl/apptest.xxx.com_bundle.crt";
  • ssl_certificate_key "/etc/nginx/ssl/apptest.xxx.com.key";
  • ssl_session_cache shared:SSL:1m;
  • ssl_session_timeout 10m;
  • ssl_ciphers HIGH:!aNULL:!MD5;
  • ssl_prefer_server_ciphers on;
  • # Load configuration files for the default server block.
  • include /etc/nginx/default.d/*.conf;
  • location /resources/ {
  • # oss内网地址
  • proxy_pass https://bucketxxx.oss-cn-chengdu-internal.aliyuncs.com/;
  • # oss内网地址
  • proxy_set_header Host bucketxxx.oss-cn-chengdu-internal.aliyuncs.com;
  • proxy_set_header X-Forwarded-Proto $scheme;
  • proxy_set_header X-Forwarded-Host $host;
  • proxy_set_header X-Forwarded-Server $host;
  • proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  • proxy_set_header X-Real-IP $remote_addr;
  • proxy_http_version 1.1;
  • proxy_set_header Upgrade $http_upgrade;
  • proxy_set_header Connection "Upgrade";
  • proxy_read_timeout 1d;
  • proxy_send_timeout 1d;
  • # 此处配置是为了把阿里云oss的返回的Content-Disposition隐藏掉,否则图片或文件在浏览器中会下载,不会显示。
  • proxy_hide_header Content-Disposition;
  • }
  • error_page 404 /404.html;
  • location = /40x.html {
  • }
  • error_page 500 502 503 504 /50x.html;
  • location = /50x.html {
  • }
  • }

配置中 proxy_hide_header Content-Disposition; 的目的是阿里云oss返回以后头部携带 Content-Disposition参数浏览器会下载图品或文件,隐藏掉以后就可以在浏览器显示图片了。

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门