快速开始

此部分基于基于 Docker 安装之 docke 与 docker-compose基于 Docker 安装之 Nginx MySQL 和 PHP 环境两篇文章,如果你的 docker-compose 文件与我文中有冲突,那么此篇文章可能并不适合你。或者你可以选择采用我的方案。

安装时为了顺利安装,请先不要开启 https,等待安装完后在开启。

建立 nginx 配置文件

nginx/conf.d文件下新建typecho.conf文件并写入如下内容:

server {
    listen   80; ## listen for ipv4; this line is default and implied

    root /usr/share/nginx/typecho/;
    index index.php index.html index.htm;

    server_name life.antmoe.com;

    gzip on;
    gzip_min_length 10240;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain text/css text/xml application/json text/javascript application/x-javascript application/xml;
    gzip_disable "MSIE [1-6]\.";

    if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php$1 last;
    }

    location ~ .*\.php(\/.*)*$ {
        try_files $uri $uri/ /index.php?$query_string;
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
        expires           5d;
    }
}

以上仅为示例,请根据具体情况修改。

上传 typecho 程序

进入lsky-release页面下载程序包,注意不要下载源码包

image-20220327130509061

将压缩包中的文件上传至www/typecho文件夹下。

查看效果

此时重启 dockerdocker-compose restart后访问设置的域名或 ip+端口号即可看到效果。

安装时服务器地址,输入ifconfig查看本机 ip 地址,并填入。

image-20220327000351433

例如我的就是172.28.0.1,数据库可以通过命令或者可视化工具链接后继续新建或者使用启动容器时创建的数据库。

关于 SSL

我的方案是采用又拍云回源服务器方式,因此服务器没必要安装 ssl 证书,只需要在又拍云处申请证书即可。

但是这样会导致样式文件无法正常显示,因此需要调整部分配置文件,

安装完成后修改程序根目录下的config.inc.php,在末尾处添加如下代码

/** 开启HTTPS */
define('__TYPECHO_SECURE__',true);

此时在 upyun 开启 https 即可。