June 02
树莓派4B安装lnmp环境搭建Typecho博客
安装 Nginx、PHP7和Mysql:
sudo apt update
sudo apt install nginx php7.3-fpm php7.3-curl php7.3-gd php7.3-mbstring php7.3-mysql php7.3-imap php7.3-opcache php7.3-xml php7.3-xmlrpc php7.3-zip uw-mailutils php-pear mariadb-server -y
sudo systemctl start php7.3-fpm.service
配置Nginx:
sudo nano /etc/nginx/sites-available/default
ctrl+w查找index,在后面加上index.php:
index index.php index.html index.htm;
再将如下内容:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
更换为:
location ~ .*\.php(\/.*)*$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$
include fastcgi_params;
}
重启Nginx服务:
sudo systemctl start nginx
配置MySQL数据库:
sudo mysql_secure_installation
#接下来按提示配置即可
创建服务库:
sudo mysql
接着执行以下代码:
create database typecho;
grant all on typecho.* to 'admin'@'localhost' identified by 'Admin123';
flush privileges;
若跟上一段执行一致的话安装博客时注意几个地方:
数据库地址:localhost
数据库用户名:admin
数据库密码:Admin123
安装Typecho博客:
cd Dwonloads
sudo wget http://typecho.org/downloads/1.1-17.10.30-release.tar.gz
sudo tar zxvf 1.1-17.10.30-release.tar.gz
sudo mv build/* /var/www/html
最后给予权限:
sudo chmod 755 /var/www/html -R
typecho伪静态
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
Nginx添加SSL证书:
server{
listen 443;
ssl on;
#填写绑定证书的域名
server_name urbanash.xyz;
#网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
#证书文件名称
ssl_certificate 1_urbanash.xyz_bundle.crt;
#私钥文件名称
ssl_certificate_key 2_urbanash.xyz.key;
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;
root /var/www/html;
index index.php index.html index.htm;
}
把http的域名请求转成https:
server {
listen 80;
server_name urbanash.xyz;
#把http的域名请求转成https
return 301 https://$host$request_uri;
}
完成!!!
腾讯云说明文档:Nginx 服务器证书安装
作者:https://urbanash.xyz/notes/typecho.html
:D 少女祈祷中...