nginx 代理 oss 节省费用

使用 nginx 代理 oss 来节省阿里云 oss 费用

我们在阿里云使用了他们的 oss用来存放录音文件,访问频繁;我们发现在内网访问不要钱,然后就想到用 nginx 走内网访问 oss 然后在对外面提供访问;

image-20201103211822428

image-20201103212119952

所以我们需要在 nginx 服务器上做如下配置

server {
    listen 80;
    server_name static.bookstack.cn;
    client_max_body_size 128M;
    location / {
        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_set_header X-NginX-Proxy true;
        # #################################################### #
        # 这里的host,必须设置为阿里云OSS分配的内网域名
        proxy_set_header Host bookstack-static.oss-cn-shenzhen-internal.aliyuncs.com;
        # 这里设置为阿里云OSS的endpoint
        proxy_pass http://oss-cn-shenzhen-internal.aliyuncs.com;
        # #################################################### #
        proxy_redirect off;
        # Socket.IO Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

这样我们就能省去阿里云oss 外网访问流量所产生的费用了

posted @ 2020-11-03 21:25  张首富  阅读(1332)  评论(0编辑  收藏  举报