恢复数据库
创建空白utf8mb4库与用户
SQL
-- 使用create database语句创建数据库
-- CREATE DATABASE IF NOT EXISTS WordPress DEFAULT CHARSET utf8;
-- drop database xxxx;
create database if not exists WordPress default character set utf8mb4 collate utf8mb4_unicode_ci;
-- 查看创建的DB的字符集,应该为utf8mb4
select schema_name,default_character_set_name from information_schema.schemata where schema_name = 'WordPress';
-- 创建用户并授权
CREATE USER 'wordPress'@'localhost' IDENTIFIED BY 'WordPress';
GRANT all privileges ON WordPress.* TO 'wordPress'@'localhost';
flush privileges;数据库恢复
Bash
$ 7za x WordPress_db.7z -pxxxx
$ ls /data/backups/WordPress_db.sql
$ sudo mariadb
MariaDB [(none)]> use WordPress;
MariaDB [WordPress]> source /data/backups/WordPress_db.sql恢复站点文件
Bash
7za x wordPress_file.7z -pxxxxx -o/data/www检查 PHP扩展模块与配置
WordPress服务器环境:PHP Extensions,本机已安装的php扩展:php -m;对比后,还需要安装:
Bash
sudo apt install php8.3-curl php8.3-gd php8.3-igbinary php8.3-imagick php8.3-intl php8.3-mbstring php8.3-mysql php8.3-zip php8.3-xml- 上传文件由默认的2M,改为5M:改完要重启php-cgi.exe
Bash
sudo vim /etc/php/8.3/fpm/php.ini # 更改 upload_max_filesize = 5M
sudo systemctl restart php8.3-fpm检查WordPress配置
/data/www/wordPress/wp-config.php 中数据库配置,及其他配置是否正确,是否需要修改?
也可以考虑使用Socket连接,但前提得创建好OS用户。
define('DB_HOST', ':/var/run/mysqld/mysqld.sock');
恢复http访问
OS路径准备
目录与文件的权限示例:
Bash
$ ll /var/log/nginx
total 492K
drwxr-xr-x 2 root adm 4.0K Oct 18 14:58 ./
drwxr-xr-x 8 root root 4.0K Oct 19 11:03 ../
-rw-r----- 1 www-data adm 465K Oct 25 19:14 access.log
-rw-r----- 1 www-data adm 8.9K Oct 25 19:30 error.log创建日志文件
Bash
sudo mkdir -p /data/www/log
sudo chown -R www-data:adm /data/www/log
sudo chmod -R u=rwx,g=rx,o=rx /data/www/log
sudo chown -R www-data:adm /data/www/wordPress
sudo chmod -R u=rwx,g=rx,o=rx /data/www/wordPress
ll /data/www/log # 与/var/log/nginx权限对比,可以不给其他用户读取权限
grep ^adm: /etc/group # 看 adm 组有哪些用户验证目录的权限:
Bash
sudo -u www-data touch /data/www/log/test
sudo -u www-data vim /data/www/log/test
sudo -u www-data rm /data/www/log/testnginx 站点配置文件:注意是http访问
Bash
sudo vim /etc/nginx/sites-enabled/blog.t725.cnNginx
server {
listen 80;
server_name blog.t725.cn;
if ($time_iso8601 ~ "^\d{2}(\d{2})-(\d{2})") {
set $year $1;
set $month $2;
}
if ($year = "") {
set $year NoDate;
}
set $logDN $host;
if ($logDN = "") {
set $logDN NoHost;
}
access_log /data/www/log/nginx_${year}${month}_${logDN}.log;
# 禁止特定bot,if中 ~*:与正则表达式匹配为真,不区分大小写;!~*:为不匹配;=:为精确匹配;!=:为精确不匹配。
if ($http_user_agent ~* (python|perl|Go-http-client|fasthttp|Apache|zgrab|Custom-AsyncHttpClient|CMS-Checker|Amazonbot|MJ12bot|AhrefsBot)) {
return 444;
}
if ($http_user_agent = -) {
return 444;
}
if ($http_user_agent = "") {
return 444;
}
root /data/www/wordPress;
index index.php index.html;
client_max_body_size 5m; # 上传文件大小上限
add_header X-Frame-Options SAMEORIGIN; # 只允许同源域名下 frame 来嵌套
add_header X-XSS-Protection "1; mode=block"; # 防止 XSS
add_header X-Content-Type-Options nosniff; # 禁止嗅探 MIME 类型
# xmlrpc.php、phpinfo.php,只有白名单ip可访问用(IP段:192.168.13.0/24),其他403;如果所有人不可用,使用 return 403。
# 由于是.php结尾,要在【location ~ \.php$ {】前面,才有效。
location ~ ^/(xmlrpc|phpInfo)\.php { # 白名单IP,
allow 10.0.0.103;
deny all;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ^~ /wp-content/uploads/20 { # 防盗链,valid_referers none blocked 可允许无引用访问,PDF.js View插件是有引用访问。
valid_referers t725.cn *.t725.cn *.google.com *.bing.com *.baidu.com;
if ($invalid_referer) {
return 302 $scheme://$host/additional/anti-theft.png;
}
}
location ^~ /dl/ {
alias /data/downloads/;
}
# php-fpm [~ 区分大小写 ~* 不区分大小写]
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location / { # WordPress 固定链接功能支持
try_files $uri $uri/ /index.php?$args;
}
}确认 http 的 blog.t725.cn 首页是否能打开
Bash
sudo nginx -t && sudo nginx -s reload如果同时更换了域名,可先只处理配置中值,其他值等网站可访问后,再处理。
SQL
select * from wp_options o WHERE o.option_name IN ('siteurl','home');将默认站点的请求,强制跳转到blog.t725.cn
Bash
sudo rm /etc/nginx/sites-enabled/default
ls /etc/nginx/sites-available/default
sudo vim /etc/nginx/sites-enabled/defaultNginx
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
access_log off;
return 301 https://blog.t725.cn;
# return 301 $scheme://blog.t725.cn$request_uri;
}
发表回复