服务器要求:
下载Typecho:
wget https://github.com/typecho/typecho/releases/latest/download/typecho.zip
unzip typecho.zip -d /var/www/typecho
/etc/nginx/conf.d/typecho.conf
):server {
listen 80;
server_name yourdomain.com; # 替换为你的域名
root /var/www/typecho; # Typecho安装目录
index index.php index.html index.htm;
# 开启伪静态
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$1 last;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.0-fpm.sock; # 根据PHP版本调整
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
# 静态文件缓存
location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|svg)$ {
expires 30d;
access_log off;
}
}
bash
nginx -t
systemctl reload nginx
登录MySQL:
mysql -u root -p
创建数据库和用户:
CREATE DATABASE typecho DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'typecho_user'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON typecho.* TO 'typecho_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
访问你的域名:http://yourdomain.com
或 http://your-server-ip
按照安装向导完成:
文件权限设置:
chown -R www-data:www-data /var/www/typecho
find /var/www/typecho -type d -exec chmod 755 {} \;
find /var/www/typecho -type f -exec chmod 644 {} \;
启用HTTPS (使用Let's Encrypt):
apt install certbot python3-certbot-nginx
certbot --nginx -d yourdomain.com
禁用目录列表: 在Nginx配置中添加:
autoindex off;
502 Bad Gateway错误:
systemctl status php8.0-fpm
伪静态不工作:
上传文件大小限制:
修改PHP配置(php.ini
):
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 128M
按照以上步骤完成后,你的Typecho博客应该已经在Nginx服务器上正常运行了。