需求:一个nginx需求,需要访问域名下的txt文件,然后通过nginx代理到oss里面某个路径
比如访问 https://card.baidu.com/1733966648479433.txt
,需要跳转到https://aaa.oss-cn-hangzhou.aliyuncs.com/prod/files/2024/12/12/1733966648479433.txt
场景:在做微信支付的时候,需要把MP文件放到oss上面,然后通过域名去直接访问
nginx配置如下:
location ~* \.(txt)$ {
proxy_pass https://aaa.oss-cn-hangzhou.aliyuncs.com;
proxy_set_header Host aaa.oss-cn-hangzhou.aliyuncs.com;
# 在 Nginx 设置中将 URI 的路径附加在 proxy_pass 的后面
rewrite ^/(.+\.txt)$ /prod/files/2024/12/12/$1 break;
}