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 外網訪問流量所產生的費用了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM