系统环境
CentOS 6.10
Nginx 1.10.2
帝国CMS 7.5
1. 下载安装包
wget http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_centos6.5_x86_64.rpm
2. 安装ossfs
ossfs需要依赖fuse 2.8.4以上版本
查看当前系统的fuse
版本
yum list fuse*
rpm -qa fuse*
低于要求版本需要先卸载
yum remove fuse fuse-devel
rpm -e fuse-XXX
重新安装fuse
各个版本安装包下载地址:https://github.com/libfuse/libfuse/releases
以fuse-2.9.9为例,下载地址:https://github.com/libfuse/libfuse/releases/download/fuse-2.9.9/fuse-2.9.9.tar.gz
# 安装依赖
yum install automake gcc-c++ git libcurl-devel libxml2-devel make openssl-devel
# 安装 fuse
wget https://github.com/libfuse/libfuse/releases/download/fuse-2.9.9/fuse-2.9.9.tar.gz
tar -zxvf fuse-2.9.9.tar.gz
cd fuse-2.9.9
./configure
make
make install
# 添加环境变量
vi /etc/profile
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
source /etc/profile
# 查看版本
pkg-config --modversion fuse
安装ossfs
yum localinstall ossfs_1.80.6_centos6.5_x86_64.rpm
3. 配置账号访问信息
echo my-bucket-name:my-access-key-id:my-access-key-secret > /etc/passwd-ossfs
chmod 640 /etc/passwd-ossfs;
4. 挂载Bucket
# -o nonempty 表示ECS本地目录可以为非空
# -o allow_other 表示允许普通用户访问,不加图片无法正常上传
ossfs img-sitename /www/www.domain.net/d/file -ourl=http://oss-cn-qingdao-internal.aliyuncs.com -o nonempty -o allow_other
ossfs sitename-skin /www/www.domain.net/skin -ourl=http://oss-cn-qingdao-internal.aliyuncs.com -o nonempty -o allow_other
5. 卸载Bucket
fusermount -u /www/www.domain.net/d/file # 正常卸载
fusermount -zu /www/www.domain.net/skin # 强制卸载(解决正常卸载报 device busy 错误)
详细参考:阿里云官方教程:ossfs安装与配置
6. Nginx重定向
location ^~ /d/file {
proxy_pass https://sitename.oss-cn-qingdao.aliyuncs.com/;
add_header Access-Control-Allow-Origin *;
}
location ^~ /skin {
proxy_pass https://sitename-skin.oss-cn-qingdao.aliyuncs.com/;
add_header Access-Control-Allow-Origin *;
}
proxy_pass
用法
第一种:
location ^~ /proxy/ {
proxy_pass http://www.domain.com/;
}
代理到URL:http://www.domain.com/filename.html
第二种(相对于第一种,最后少一个 / )
location ^~ /proxy/ {
proxy_pass http://www.domain.com;
}
代理到URL:http://www.domain.com/proxy/filename.html
第三种:
location ^~ /proxy/ {
proxy_pass http://www.domain.com/path/;
}
代理到URL:http://www.domain.com/path/filename.html
第四种(相对于第三种,最后少一个 / )
location ^~ /proxy/ {
proxy_pass http://www.domain.com/path;
}
代理到URL:http://www.domain.com/pathfilename.html
详细参考:nginx 之 proxy_pass详解
eg: 网站代理到OSS对象存储
location ^~ /d/file/p {
proxy_pass https://sitename.oss-cn-qingdao.aliyuncs.com/p;
add_header Access-Control-Allow-Origin *;
}
访问:http://www.domain.net/d/file/p/2020-03-10/3c750e47d237e069aaa10cdc9ebdba0c.jpg
转到:https://img-sitename.oss-cn-qingdao.aliyuncs.com/p/2020-03-10/3c750e47d237e069aaa10cdc9ebdba0c.jpg