搭建网站(以typecho例子)
系统:Debian12
绑定域名
修改host配置
vim /etc/hosts
添加需要绑定的域名,格式
公网ip 域名
二.配置 MySQL 数据库
进入Mysql
mysql -u root -p
创建数据库
CREATE DATABASE typecho_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'typecho_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON typecho_db.* TO 'typecho_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
下面自行替换
数据库名:typecho_db
用户名:typecho_user
密码:your_password
导入备份数据(如果没有可以跳过)
切换数据库
USE existing_database_name;
将 existing_database_name 替换为您想要导入数据的现有数据库的名称。
导入备份数据
SOURCE /path/to/backup_file.sql;
将 /path/to/backup_file.sql 替换为您备份文件的完整路径。
三.配置 Nginx
打开nginx配置目录/etc/nginx/
,在sites-available
文件夹中新建typecho
的配置文件typecho.conf
sudo vim /etc/nginx/sites-available/typecho.conf
写入typecho的反代配置信息
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name your_domain.com; # 将 your_domain.com 替换为您的域名
ssl_certificate /**/**/*.cer; # 填入SSL证书路径
ssl_certificate_key /*/*/*.key;# 填入SSL证书路径
root /var/www/typecho; # Typecho 博客系统文件夹路径,请根据您的实际路径进行替换
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock; # 根据您的 PHP 版本和配置进行替换
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.(jpg|jpeg|gif|png|webp|ico|bmp|tiff|css|js|svg)$ {
expires max;
log_not_found off;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log /var/log/nginx/typecho_access.log;
error_log /var/log/nginx/typecho_error.log;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types text/plain text/css text/xml application/xml application/javascript application/rss+xml application/atom+xml image/svg+xml;
}
启动服务器
如果没有SSL证书需要将https相关的语法用#注释掉
检查配置文件语法错误:
nginx -t
重新加载配置文件
nginx -s reload
四.申请SSL证书
1.acme.sh手动安装
克隆仓库(或直接下载解压)
git clone --depth=1 https://github.com/acmesh-official/acme.sh && cd acme.sh
国内使用Gitee镜像
git clone --depth=1 https://gitee.com/neilpang/acme.sh && cd acme.sh
安装
./acme.sh --install
注册账号
acme.sh --register-account -m my@example.com
2.生成证书
http 方式需要在你的网站根目录下放置一个文件, 来验证你的域名所有权,完成验证. 然后就可以生成证书了.
.\acme.sh --issue -d mydomain.com -d www.mydomain.com --webroot /home/wwwroot/mydomain.com/
3.填入证书
将证书填入代理消息
ssl_certificate:填入SSLCertificateChainFile路径
ssl_certificate_key:填入SSLCertificateKeyFile路径
4.重启Nginx
检查配置文件语法错误:
nginx -t
重新加载配置文件
nginx -s reload