鉴于近期1M的华盛顿小鸡访问速度太慢,申请了Azure的机器(Debian)来重新部署,因此需要搭建一套Typecho,首先要做的就是完成基础Nginx的部署和SSL证书的访问。以下操作建议切换至root,避免权限问题。
一、Nginx环境搭建。
目标:通过IP或者域名能够以80端口打开Nginx初始页面
1、更新系统环境
apt update
2、自动化安装Nginx
apt install nginx
3、此时已能正常打开页面(index.html)
二、配置SSL证书并自动更新
该章节内容主要基于Github(https://github.com/acmesh-official/acme.sh)进行执行,适当根据需要做了部分调整。
1、执行acme.sh,将email后的邮箱调整为自己邮箱
curl https://get.acme.sh | sh -s [email protected]
执行完毕该脚本后,可看到①当前目录下生成了.acme.sh/;②自动创建了cronjob定任务, 每天 0:00 点自动检测所有的证书并更新。
2、生成证书,本初主要采用手动DNS方式
Ⅰ、调用发行命令获取CDN(Cloudflare)所需配置信息,将mydomain.com调整为自己的域名。并在Cloudflare添加一条TXT记录(见下图1、图2)。若出错则执行source ~/.bashrc
acme.sh --issue --dns -d mydomain.com --yes-I-know-dns-manual-mode-enough-go-ahead-please

图1

图2
Ⅱ、Cloudflare配置完并保存后,执行renew命令,则可生成证书
acme.sh --renew -d mydomain.com --yes-I-know-dns-manual-mode-enough-go-ahead-please
Ⅲ、至此证书申请环节已完成,放置在域名文件夹下
三、Nginx配置SSL
1、将上一步生成的证书拷贝到Nginx目录下。新建文件夹并执行命令。
touch /etc/nginx/ssl_key/
acme.sh --install-cert -d example.com --key-file /etc/nginx/ssl_key/key.pem --fullchain-file /etc/nginx/ssl_key/cert.pem --reloadcmd "systemctl force-reload nginx"
2、修改ngxin配置文件。此处需注意默认配置文件的defaul情况。此处采用新建配置文件形式。
cd /etc/nginx/conf.d/
touch my_blog.conf
3、调整配置文件内容,本配置以php为准,因用于搭建typecho。
server {
# 监听HTTP默认的80端口
listen 80;
# 如果80端口出现访问该域名的请求
server_name myexample.com;
# 将请求改写为HTTPS(这里写你配置了HTTPS的域名)
rewrite ^(.*)$ https://www.leaou.com;
}
server {
listen 443 ssl;#设置SSL功能
server_name leaou.com www.leaou.com; #localhost修改为证书绑定的域名
root /var/www/html;
index index.php;
ssl_certificate /etc/nginx/ssl_key/cert.pem; #证书的文件名
ssl_certificate_key /etc/nginx/ssl_key/key.pem; #证书的密钥文件名
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #加密套件
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #配置协议
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/leaou.com_access.log;
error_log /var/log/nginx/leaou.com_error.log;
client_max_body_size 64M;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_read_timeout 3600s;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}
}
4、重启Nginx即可
systemctl restart nginx
至此已完成Nginx的配置和正常SSL的证书访问,之后也可通过Cloudflare再次进行配置。