在配置过程中,我遇到了一直出现nginx欢迎页的bug,后面发现是us.kg域名的问题,在我换成blog域名后成功了,问题出现的原因可能是前段时间us.kg崩了,于是我从cloudflare中删除了该域名,后面添加回来,可能是没有清除以前的dns记录导致的?我没有验证,大家可以自行尝试。
1. 更新系统
1 2 3
| sudo -i apt update apt upgrade -y
|
2. 安装 Nginx
1 2 3
| apt install nginx -y systemctl start nginx systemctl enable nginx
|
3. 安装MySQL(MariaDB)
1 2 3
| apt install mariadb-server -y systemctl start mariadb systemctl enable mariadb
|
配置数据库
1
| mysql_secure_installation
|
在执行 mysql_secure_installation 时,会问你几个问题:
- Enter current password for root: 直接按回车
- Set root password? [Y/n]:输入 Y,然后设置 root 密码
- Remove anonymous users? [Y/n]:输入 Y
- Disallow root login remotely? [Y/n]:输入 Y
- Remove test database? [Y/n]:输入 Y
- Reload privilege tables now? [Y/n]:输入 Y
4. 为 Typecho 创建数据库和用户
- 使用 root 身份连接 mysql -u 表示指定用户名 -p 表示需要输入密码
1 2 3 4 5
| CREATE DATABASE typecho; CREATE USER 'typecho'@'localhost' IDENTIFIED BY '设置一个密码'; GRANT ALL PRIVILEGES ON typecho.* TO 'typecho'@'localhost'; FLUSH PRIVILEGES; exit;
|
- 创建名为 typecho 的数据库,并创建一个 typecho 用户,指定其此用户仅允许本地访问,且设置一个密码,然后授予该用户对 typecho 数据库的所有权限。最后刷新一下。
5.安装 PHP 及必要扩展
1 2 3
| apt install php-fpm php-mysql php-gd php-curl php-mbstring php-xml php-zip -y systemctl start php8.3-fpm systemctl enable php8.3-fpm
|
1 2 3 4
| dpkg -l | grep php-fpm
|
6. 下载和配置 Typecho
1 2 3 4 5 6 7 8 9 10
| cd /var/www/html rm /var/www/html/index.nginx-debian.html mkdir typecho cd typecho wget https://github.com/typecho/typecho/releases/latest/download/typecho.zip apt install unzip -y unzip typecho.zip chown -R www-data:www-data /var/www/html/typecho chmod -R 755 /var/www/html/typecho chmod -R 777 /var/www/html/typecho/usr/uploads
|
7. 配置 Nginx
1
| vim /etc/nginx/sites-available/typecho.conf
|
添加以下信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| server { listen 80; server_name example.com;
if ($http_x_forwarded_proto != 'https'){ return 301 https://$server_name$request_uri; } }
server { listen 443 ssl; server_name example.com;
ssl_certificate /etc/nginx/ssl/cert.pem; ssl_certificate_key /etc/nginx/ssl/key.pem;
ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 1d;
root /var/www/html/typecho; index index.php;
add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin";
location / { try_files $uri $uri/ /index.php?$args; }
location ~ \.php$ { include fastcgi_params; fastcgi_param HTTPS on; fastcgi_pass unix:/run/php/php8.3-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
location ~ /\.(?!well-known) { deny all; }
}
|
- 如果你的域名挂在cloudflare,你可以通过进入域名,
SSL/TLS—>源服务器—>创建证书
修改nginx.conf,记得备份,将原有的nginx.conf替换成如下配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| user www-data; worker_processes auto; worker_rlimit_nofile 65535; pid /run/nginx.pid;
error_log /var/log/nginx/error.log notice;
events { use epoll; worker_connections 8192; multi_accept on; }
http { include /etc/nginx/mime.types; default_type application/octet-stream;
log_format combinedio '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" ' '$request_length $request_time $upstream_response_time';
access_log /var/log/nginx/access.log combinedio;
sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; client_body_timeout 12; client_header_timeout 12;
server_tokens off;
gzip on; gzip_types text/css application/json application/javascript;
include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/typecho.conf; }
|
验证配置:
8. 启用站点配置
1 2 3 4
| ln -sf /etc/nginx/sites-available/typecho.conf /etc/nginx/sites-enabled/ rm /etc/nginx/sites-enabled/default nginx -t systemctl restart nginx
|
9. 访问网站完成安装
现在你可以通过浏览器访问你的域名或服务器 IP,会看到 Typecho 的安装界面。按照以下步骤完成安装:

- 选择 “开始安装”
- 数据库适配器选择 “MySQL”
- 数据库地址填写 “localhost”
- 数据库端口保持默认 “3306”
- 数据库用户名填写 “typecho”
- 数据库密码填写你之前设置的密码
- 数据库名填写 “typecho”
- 点开高级选项,取消启用数据库 SSL 服务端证书验证
- 创建管理员账号和密码

10.注意事项:
- 确保防火墙允许 80 端口访问:
1 2 3 4
| apt install ufw ufw allow 80/tcp ufw allow 443/tcp ufw enable
|
- 如果遇到权限问题,可以检查:
1 2
| chmod -R 755 /var/www/html/typecho chown -R www-data:www-data /var/www/html/typecho
|
- 如果网站打不开,可以查看日志:
1
| tail -f /var/log/nginx/error.log
|
- 记得定期备份数据:
1
| mysqldump -u root -p typecho > typecho_backup.sql
|
11.常用指令
首先得进入 mysqlmysql -u root -p
- 更改 mysql root 密码:
1
| ALTER USER 'root'@'localhost' IDENTIFIED BY 'F)!1x5n1>4>ipf,rUXrQaA1D0d';
|
- 查看数据库中的用户表:
1
| SELECT * FROM typecho_users;
|
- 重置管理员 url:
1
| UPDATE typecho_users SET url = 'https://新域名' WHERE uid = 1;
|
- 修改管理员用户名:
1
| UPDATE typecho_users SET name = '新管理员用户名' WHERE name = 'admin';
|
- 重置管理员密码:
1
| UPDATE typecho_users SET password = MD5('新密码') WHERE uid = 1;
|
参考链接?:https://ecouu.com/archives/41/