wordpress博客迁入

1丶上传需要恢复的文件

1.mysql 数据库数据文件

all-databases3306.sql
Bash

2.wordpress 博客:/var/www/html 文件夹压缩包

html.tar.gz
Bash

2、安装 docker

1.更新系统软件包列表

sudo apt-get update
Bash

2.安装 Docker

sudo apt install docker.io
Bash

3.启动 Docker 服务

sudo systemctl start docker
Bash

4.设置 Docker 服务开机自启动

sudo systemctl enable docker
Bash

5.查看 Docker 版本信息,确认安装成功

docker --version
Bash

3丶docker 拉取 mysql:8.0.20,并配置

1.拉取镜像

docker pull mysql:8.0.20
Bash

2.运行 mysql 容器

docker run -d --restart=always --security-opt seccomp=unconfined --name mysql -p 3360:3306 -e MYSQL_ROOT_PASSWORD=password mysql:8.0.20
Bash
–restart=always:开启容器自启动;
–security-opt seccomp=unconfined:取消 Seccomp 的限制,使容器内的进程可以访问所有系统调用,防止mysql容器异常停止;
-p 3360:3306:将 mysql 的 3306 端口映射到宿主服务器的 3360 端口;
-e MYSQL_ROOT_PASSWORD=password:配置 mysql 用户 root 的密码为 password

3.拷贝all-databases3306.sql 文件到 mysql 容器内

docker cp ./all-databases3306.sql mysql:/home
Bash

4.进入 mysql 容器,26d3 为容器 id 的前四位

docker exec -it 26d3 /bin/bash
Bash

5.登录mysql,注:-p 后紧跟密码,无空格

mysql -u root -ppassword
Bash

6.修改 mysql 服务器用户 root 的身份验证方法为 mysql_native_password

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
Bash
mysql8 所要求的验证方式为 caching_sha2_password,而当前 PHP 版本中所带的 mysqlnd 无法支持这种验证,PHP 默认的是 mysql_native_password ,所以修改 mysql 服务器用户 root 的身份验证方法为 mysql_native_password;

查看更新结果:

mysql> use mysql;
Reading table information for completion of table and column name
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.01 sec)
Bash

7.刷新用户权限

flush privileges;
Bash

8.创建wordpress数据库

create database wordpress;
Bash

9.切换到wordpress数据库

use wordpress;
Bash

10.加载之前导出的数据库

source /home/all-databases3306.sql;
Bash

11.在wp_options表中更新访问博客资源地址为https://bestr.top

update wp_options set option_value='https://bestr.top' where option_name in ('siteurl','home');
Bash

查看更新结果:

mysql> use wordpress;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from wp_options where option_name in ('siteurl','home');
+-----------+-------------+-------------------+----------+
| option_id | option_name | option_value      | autoload |
+-----------+-------------+-------------------+----------+
|         2 | home        | https://bestr.top | yes      |
|         1 | siteurl     | https://bestr.top | yes      |
+-----------+-------------+-------------------+----------+
2 rows in set (0.00 sec)
Bash

12.退出mysql

quit;
Bash

13.退出容器

exit
Bash

4丶docker 拉取 wordpress,并配置

1.拉取镜像

docker pull wordpress:latest
Bash

2.运行 wordpress 容器

docker run -d --restart=always --name wordpress -p 8080:80 wordpress:latest
Bash

3.解压 html 压缩包

tar -xzvf html.tar.gz
Bash

4.在wp-config.php中配置服务器地址和密码

vim ./html/wp-config.php
Bash
/** Database password :mysql密码 */
 define( 'DB_PASSWORD', 'password' );
 
 /** Database hostname :ip:3360 */
 define( 'DB_HOST', 'server-public-ip:3360' );
PHP

5.拷贝 html 文件夹到 wordpress 容器内

docker cp ./html wordpress:/var/www
Bash

5丶安装 nginx

1.安装nginx

sudo apt install -y nginx
Bash

2.启动nginx

sudo systemctl start nginx
Bash

其他nginx操作

sudo systemctl stop nginx:停止Nginx服务
sudo systemctl reload nginx:重新加载Nginx配置
sudo systemctl restart nginx:重新启动Nginx服务

查看Nginx服务的当前状态:

root@VM98783:~# sudo systemctl status nginx
 nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: enabled)
     Active: active (running) since Sat 2025-09-27 07:59:16 UTC; 1 weeks 2 days ago
       Docs: man:nginx(8)
    Process: 295281 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
   Main PID: 72626 (nginx)
      Tasks: 2 (limit: 1042)
     Memory: 9.3M
     CGroup: /system.slice/nginx.service
             ├─ 72626 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             └─295282 nginx: worker process
Bash

查看Ngnx相应配置文件是否有错误:

root@VM98783:~# nginx -t -c /etc/nginx/nginx.conf
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Bash

6、后续其他工作

6.1准备域名

6.2申请证书

6.3确认Nignx配置

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or WordPress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;
                                                                                                                                                
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html index.php;

        server_name _;

        # 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.4-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;
        #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

server {

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html index.php;
        server_name www.bestr.top bestr.top; # managed by Certbot

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header REMOTE-HOST $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://127.0.0.1:8080;
        }

        # 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.4-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;
        #}

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/bestr.top/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/bestr.top/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = www.bestr.top) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = bestr.top) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80 ;
    listen [::]:80 ;
                                                                                                                                                
    server_name www.bestr.top bestr.top;
    return 404; # managed by Certbot

}
Nginx
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇