不使用宝塔面板 安装 EasyImage 简单图床

发布于 2023-07-17 在 https://chenhaotian.top/linux-app/easy-image/

前言

如果不希望安装宝塔面板或其国际版 aapanel(尽管宝塔面板可以在安装后关闭),那么可以参考这篇文章。

本文安装环境为 Debian 11, 在 Ubuntu 20.04 测试通过

安装 PHP

安装 PHP 7.4

bash 复制代码
apt update -y
apt install php7.4 php7.4-fpm 

安装 PHP 拓展

bash 复制代码
apt install php7.4-fileinfo php7.4-iconv php7.4-zip php7.4-mbstring php7.4-gd

配置 PHP

bash 复制代码
vim /etc/php/7.4/fpm/php.ini

查找 upload_max_filesize post_max_size memory_limit ,按需求设置。

重启 PHP

bash 复制代码
systemctl restart php7.4-fpm

安装 Nginx

安装 Nginx

bash 复制代码
apt install nginx

拉取网站代码

bash 复制代码
cd /var/www/html
git clone https://github.com/icret/EasyImages2.0.git

赋予适当权限

bash 复制代码
chmod -R 755 /var/www/html/EasyImages2.0/
chown -R www-data:www-data /var/www/html/EasyImages2.0/

配置 Nginx

bash 复制代码
rm /etc/nginx/sites-enabled/default
vim /etc/nginx/sites-enabled/default

填入以下配置,注意更改域名

此时不需要配置 443 监听和 SSL,之后由 Certbot 自动配置

bash 复制代码
server {
    server_name image.example.com;  # 你的域名
    listen 80;
    root /var/www/html/EasyImages2.0/;
    index index.php index.html;

    client_header_timeout 300s;
    client_body_timeout 300s; # 防止大图片上传超时
    client_max_body_size 2000m; # 应不小于100m,防止上传大图片 HTTP 413 错误

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~* ^/(config|docs|i|public)/.*\.(php|php5)$ {
        deny all; # 安全设置
    }
}

检查配置文件

bash 复制代码
nginx -t

如果出现以下内容表示正常

bash 复制代码
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

重启 Nginx

bash 复制代码
systemctl restart nginx

使用 Certbot 为 Nginx 配置 SSL 证书

bash 复制代码
apt install certbot python3-certbot-nginx
certbot --nginx -d your_domain #你的域名

测试证书自动更新

bash 复制代码
certbot renew --dry-run

安装环境部署完毕,访问你的域名即可进行网站初始化。

如果一切正常,检测结果应为全部通过。

注意事项 / 提示

  • 官方 Github 仓库:https://github.com/icret/EasyImages2.0/

  • 所有操作以 root 权限进行

  • Vim 的操作可自行寻找教程或询问 ChatGPT

  • 更改 PHP 和 Nginx 配置文件后记得重启

    bash 复制代码
    systemctl restart php7.4-fpm
    systemctl restart nginx
  • 从其他图床迁移图片后记得更改图片权限为 0755 (或0644) 和 www-data

    bash 复制代码
    chmod -R 755 /var/www/html/EasyImages2.0/
    chown -R www-data:www-data /var/www/html/EasyImages2.0/
相关推荐
哥布林学者6 天前
图床创建:github+Picgo+obsidian 带有同步删除的自动上传
图床
哥布林学者7 天前
图床创建:github+Picgo+obsidian 可以同步删除的自动上传
图床
莱茵不哈哈6 个月前
My图床项目
api·base·图床
Dong雨10 个月前
写作利器:如何用 PicGo + GitHub 图床提高创作效率
github·typora·picgo·图床
Arciab1 年前
个人图床配置,实现博客园图片上传自由
picgo·图床
一个很帅的帅哥1 年前
Mac在Typora配置PicGo图床,以github为例
macos·gitee·github·typora·mac·图床
阿甘知识库1 年前
为什么 AVIF 将成为下一代图片格式之王
压缩·图床·avif
阿甘知识库1 年前
美团图床设置教程
cdn·图床
区区一散修1 年前
GitHub图床
github·图床
sssugarr1 年前
使用North自部署图床服务
linux·图床·自部署