[mac]-使用pic-go和linux服务器搭建自己的图床
导语:今天发现gitee图床上的图片无法访问了,似乎设置了防盗。还是用自己的服务器稳一点,虽然没有域名,如果更换服务器ip会比较麻烦。sftp 或者gitlab 这些都可以直接在服务器上安装使用。打算使用sftp就算更换服务器的话也方便一点。参考https://github.com/imba97/picgo-plugin-sftp-uploader如果需要用服务器私钥登录且没有密钥 需要生成密钥#
导语:今天发现gitee图床上的图片无法访问了,似乎设置了防盗,码云也经常出问题。还是用自己的服务器稳一点,虽然没有域名,如果更换服务器ip会比较麻烦。
sftp 或者gitlab 这些都可以直接在服务器上安装使用。
打算使用sftp 就算更换服务器的话也方便一点。
参考
https://github.com/imba97/picgo-plugin-sftp-uploader
如果需要用服务器私钥登录且没有密钥 需要生成密钥
# 执行命令一直确认 使用默认配置
ssh-keygen
先到服务器上把原先的图片下载下来
mkdir /blog
cd /blog
git@gitee.com:jiaminxu/BlogImage.git
mkdir -p /blog/BlogImage/img2/
chown -R ubuntu:ubuntu /blog
chmod -R 777 /blog
# 给原来的文件做软连接 使后面依旧可以访问
ln -s /blog/BlogImage/img/* /blog/BlogImage/img2/
比如我服务器有这样一个路径:/blog/BlogImage/img/
,图片在里面
我的网站根目录是/blog/BlogImage/
那么我可以把网址路径设置为/uploads/{year}/{month}/{fullName}
文件路径设置为/blog/BlogImage/img/{year}/{month}/{fullName}
我自己是设置为了/blog/BlogImage/img2/{fullName}
在电脑上设置一个文件 以mac为例
{
"imba97": {
"url": "https://imba97.cn",
"path": "/uploads/{year}/{month}/{fullName}",
"uploadPath": "/www/imba97_cn/uploads/{year}/{month}/{fullName}",
"host": "1.2.3.4",
"port": 22,
"username": "root",
"privateKey": "C:/Users/imba97/.ssh/id_rsa",
"passphrase": "private_key_password",
"fileUser": "www",
"dirMode": "0755"
},
"btools": {
"url": "https://btools.cc",
"path": "/uploads/{year}/{month}/{fullName}",
"uploadPath": "/www/btools_cc/uploads/{year}/{month}/{fullName}",
"host": "1.2.3.4",
"username": "root",
"password": "ssh_password"
}
}
我这里使用密码连接
/Users/xujiamin/blog_upload.json
{
"tx": {
"url": "http://1.117.21.54",
"path": "/img2/{fullName}",
"uploadPath": "/blog/BlogImage/img2/{fullName}",
"host": "1.117.21.54",
"username": "username",
"password": "password"
}
安装一个nginx
# cent
yum -y install nginx
# ubuntu
apt install nginx
添加一个图片的解析
location ~ .*\.(gif|jpg|jpeg|png|jfif)$ {
root /blog/BlogImage/ ;
autoindex on ;
}
重新加载nginx配置
nginx -s reload
在线测试结果
更多推荐
所有评论(0)