根据文章记录,已尝试Jekyll、Ghost等多种博客,实际对markdown的兼容性均表现一般,最终还是觉得
环境:Ubuntu 18.04 x86_64
前期准备
- 设置ssh、创建一个非root用户,并赋予root权限,可参考ssh免密登录设置
- 安装
apt-get install nginx
apt-get install mysql-server-5.7
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
apt-get install php7.2-fpm php7.2-mysql
编辑nginx配置文件,取消php和默认部分的注释,将php版本改为7.2,即如下内容:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
location ~ /\.ht {
deny all;
}
-
(可选)安装phpadmin
apt-get install phpmyadmin ln -s /usr/share/phpmyadmin/ /var/www/html/phpMyAdmin
随后即可通过访问IP/phpMyAdmin访问
配置数据库
-
创建WordPress操作的数据库和用户
mysql -u root -p CREATE DATABASE blog;
CREATE USER blog@localhost;
SET PASSWORD FOR blog@localhost=PASSWORD("password");
GRANT ALL PRIVILEGES ON blog.* TO blog@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
QUIT;如果是从备份恢复,将备份的blog.sql上传到服务器,执行
mysql -u root -p blog<blog.sql
完成数据库的备份。配置SSL
这里参考《利用certbot手动申请Let’sEncrypt免费SSL证书》使用certbot申请SSL证书,也可用其他方式自备证书。
Nginx
mkdir -p /var/www/blog
cd /var/www/blog
tar -xzvf blog.tar.gz
rm /var/www/blog/.user.ini
chown -R www-data:www-data /var/www/blog/
vim /etc/nginx/conf.d/blog.conf
粘贴下列内容
server {
listen 80;
#listen [::]:80;
server_name blog.39hope.com;
return 301 https://$http_host$request_uri;
#rewrite ^ https://$server_name$request_uri? permanent;
}
server {
# SSL configuration
listen 443 ssl http2;
#listen [::]:443 ssl http2;
root /var/www/blog;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name blog.39hope.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/blog.39hope.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.39hope.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /var/log/nginx/blog.log;
}
后续优化
旧文可参考WordPress建站记录,这里列举现在选用的插件和修改。
pwa插件:支持谷歌提出的Progressive Web App