# 先把静态资源上传或同步到 OSS,如果使用其他工具上传,注意设置文件 HTTP 头

# Bucket ACL 设置为 公共读

# 防盗链需要添加 网站域名 和 ossEndPoint域名

# 跨域设置需要添加 网站域名 和 ossEndPoint域名

# 在最前端的 nginx 代理服务器上进行设置

$ cd /etc/nginx
$ vim conf.d/domain.conf

...

# 以下为两种示例,第一条是整个目录 rewrite,第二个是二级目录指定后缀文件 rewrite

# 根据自己的 OSS 所在地域和 域名,自行替换 yourBucket 和 yourEndPoint

location /static/ {
            rewrite ^/static/(.*)$ https://yourBucket.oss-cn-yourEndPoint.aliyuncs.com/static/$1 permanent;
            add_header Access-Control-Allow-Origin 'https://yourBucket.oss-cn-yourEndPoint.aliyuncs.com';
            access_log off;
}

location ~ /file/.*\.(svg|eot|ico|woff|woff2|ttf|js|css|png|json|txt)$ {
            rewrite ^/file/(.*)$ https://yourBucket.oss-cn-yourEndPoint.aliyuncs.com/file/$1 permanent;
            add_header Access-Control-Allow-Origin 'https://yourBucket.oss-cn-yourEndPoint.aliyuncs.com';
            access_log off;
}

# 设置完成后重启 nginx

本文原创地址:https://www.linuxprobe.com/ali-oss.html作者:吴向平,审核员:逄增宝

本文原创地址:https://www.linuxprobe.com/ali-oss.html编辑:xiangping wu,审核员:暂无