千家信息网

如何使用workpress搭建个人博客网站

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,本篇内容介绍了"如何使用workpress搭建个人博客网站"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所
千家信息网最后更新 2026年11月03日如何使用workpress搭建个人博客网站

本篇内容介绍了"如何使用workpress搭建个人博客网站"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

前面几篇文章已经介绍了怎么在Linux下搭建LNMP环境:

1.安装MySQL/MariaDB

2.安装PHP

3.安装Nginx

4.nginx配置虚拟主机

接下来开始使用workpress搭建个人博客网站:

workpress官网:https://cn.wordpress.org/

下载workpress:

[root@linux ~]# wget https://cn.wordpress.org/latest-zh_CN.tar.gz

解压:

[root@linux ~]# tar -zxvf latest-zh_CN.tar.gz

创建博客网站目录:

[root@linux ~]# mkdir -p /data/www/test.blog.com

将workpress安装包中的文件移动到博客网站目录下:

[root@linux ~]# mv wordpress/* /data/www/test.blog.com/

修改nginx虚拟主机配置文件:

[root@linux ~]# vi /etc/nginx/conf.d/default.conf

修改以下内容:

1.定义博客网站的自定义域名(如有真实域名可以使用真实域名)
2.定义博客网站的目录
3.添加index.php(WordPress使用的是php)
4.将该配置文件底部的php段内容的注释符号#去掉,定义网站的目录
5.修改/scripts为网站目录路径

验证配置文件并重载:

[root@linux ~]# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful[root@linux ~]# nginx -s reload

Windows上修改hosts文件内容为:

打开浏览器访问test.blog.com:

#wordpress的页面已成功显示

接下来创建博客网站的数据库:

登录:

[root@linux ~]# mysql -uroot -p123456Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 12Server version: 10.3.18-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>

创建数据库:

MariaDB [(none)]> create database wordpress;Query OK, 1 row affected (0.000 sec)

创建用户:

MariaDB [(none)]> grant all on wordpress.* to 'blog'@'127.0.0.1' identified by 'test123';Query OK, 0 rows affected (0.029 sec)

#创建用户blog,密码test123,授权从127.0.0.1连接

修改网站目录文件的属主:

[root@linux ~]# cd /data/www/test.blog.com/[root@linux test.blog.com]# chown -R php-fpm .

打开浏览器访问test.blog.com开始配置数据库信息:

#输入好数据库信息点击提交即可

开始安装:

#定义网站标题,用户名,密码(邮件地址必填,但未配置邮件服务不会发邮件)

填写完成后点击安装,显示成功:

再次访问自定义的域名test.blog.com即可显示出博客页面:

在页面下方点击登录后进入后台管理页面:

接下来就可以自由编辑博客的主页排版、外观样式、权限等设置了。


discuz官网:https://www.discuz.net/forum.php

安装git:

[root@linux ~]# yum -y install git

通过git的方式克隆discuz包到本机:

[root@linux ~]# git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git

拷贝discuz包中的upload目录到/data/www/路径下并重命令目录:

[root@linux ~]# cp -r DiscuzX/upload/  /data/www/test.bbs.com

添加nginx虚拟主机配置文件:

[root@linux ~]# cd /etc/nginx/conf.d/[root@linux conf.d]# cp default.conf bbs.conf

编辑配置文件:

[root@linux conf.d]# vi bbs.conf

修改以下内容:

1.定义bbs网站的自定义域名(如有真实域名可以使用真实域名)
2.定义bbs网站的目录
3.添加index.php(discuz使用的是php)
4.将该配置文件底部的php段内容的注释符号#去掉,定义bbs网站的目录
5.修改/scripts为bbs网站目录路径

验证配置文件并重载:

[root@linux conf.d]# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful[root@linux conf.d]# nginx -s reload

更改目录属主:

[root@linux conf.d]# cd /data/www/test.bbs.com/root@linux test.bbs.com]# chown -R php-fpm config/ data/ uc_server/data/ uc_client/data/

修改Windows系统C:\Windows\System32\drivers\etc\hosts文件:(使用真实域名并已解析到服务器IP地址可忽略此步)

#添加自定义域名:test.bbs.com

打开浏览器访问域名即可开始安装:

点击我同意之后继续点击下一步需要配置数据库信息:

登录数据库:

[root@linux test.bbs.com]# mysql -uroot -p123456Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 92Server version: 10.3.18-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>

创建bbs网站数据库:

MariaDB [(none)]> create database bbs;Query OK, 1 row affected (0.000 sec)

创建授权用户:

MariaDB [(none)]> grant all on bbs.* to 'bbsuser'@'127.0.0.1' identified by 'test123';Query OK, 0 rows affected (0.005 sec)

#创建用户bbsuser,密码test123,授权从127.0.0.1连接

填写数据库信息:

#数据库信息填写刚创建的,管理员信息自己设置密码即可,邮箱默认即可

完成安装后bbs网站就搭建完成:

使用管理员账号登录后台:

接下来即可开始自由设置bbs网站了!
--------------------------------------------------------------------------------------------------

nginx配置多个域名:

编辑nginx虚拟主机配置文件:

[root@linux ~]# vi /etc/nginx/conf.d/default.conf

在server_name项新增域名www.blog.com:

验证配置并重载:

[root@linux ~]# nginx -t && nginx -s reload

接下来即可通过新域名www.blog.com访问该网站:

nginx配置域名重定向/跳转:

编辑nginx虚拟主机配置文件:

[root@linux ~]# vi /etc/nginx/conf.d/default.conf

添加如下内容:

    if ( $host = test.blog.com )        {           rewrite /(.*) http://www.blog.com/$1 permanent;        }

验证配置并重载:

[root@linux ~]# nginx -t && nginx -s reloadnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful

测试:

[root@linux ~]# curl -x127.0.0.1:80  -I test.blog.comHTTP/1.1 301 Moved PermanentlyServer: nginx/1.16.1Date: Sun, 13 Oct 2019 15:24:43 GMTContent-Type: text/htmlContent-Length: 169Connection: keep-aliveLocation: http://www.blog.com/

#http状态码301,Location: http://www.blog.com/,对test.blog.com的请求已成功跳转到www.blog.com,对于搜索引擎来说,test.blog.com被认为是旧域名,而优先访问新域名www.blog.com

永久重定向:permanent http状态码:301 (域名重定向使用,转移域名权重)
临时重定向:redirect http状态码:302 (非域名跳转使用,比如文件跳转)

编辑nginx虚拟主机配置文件:

[root@linux ~]# vi /etc/nginx/conf.d/default.conf

nginx添加文件跳转:

rewrite /1.txt /2.txt redirect;

验证配置并重载:

[root@linux ~]# nginx -t && nginx -s reloadnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful

测试:

[root@linux ~]# curl -x127.0.0.1:80  -I www.blog.com/1.txtHTTP/1.1 302 Moved TemporarilyServer: nginx/1.16.1Date: Sun, 13 Oct 2019 15:45:17 GMTContent-Type: text/htmlContent-Length: 145Location: http://www.blog.com/2.txtConnection: keep-alive

#http状态码:302,Location: http://www.blog.com/2.txt,文件跳转成功


Nginx双重用户认证:
适用于一些网站的重要页面(比如:管理员登录的后台管理页面),双重认证的效果就是在打开重要页面输入账号密码登录之前先验证一次用户双重认证的用户名和密码。

打开个人博客网站管理员登录页面:

修改nginx虚拟主机配置文件给当前页面wp-login.php添加双重用户认证:

[root@linux ~]# vi /etc/nginx/conf.d/default.conf

添加以下内容:

 location ~ wp-login.php                                   {            auth_basic "Auth";            auth_basic_user_file /etc/nginx/user_passwd;            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  /data/www/test.blog.com$fastcgi_script_name;            include        fastcgi_params;        }

并将root、index项的location去掉,使之变为全局配置:

由于添加的配置内容定义了双重用户验证配置为/etc/ngninx/user_passwd,但当前没有这个文件,需要使用htpasswd命令生成该文件:

安装httpd-tools包:

[root@linux ~]# yum -y install httpd-tools

生成配置文件并添加认证用户:

[root@linux ~]# htpasswd -c /etc/nginx/user_passwd admin1New password: Re-type new password: Adding password for user admin1

#生成user_passwd文件并增加认证用户admin1并设置密码,-c 参数:创建,首次生成认证配置文件使用

需要新增认证用户使用-m 参数(MD5加密):

[root@linux ~]# htpasswd -m /etc/nginx/user_passwd admin2New password: Re-type new password: Adding password for user admin2

查看用户认证配置文件即可看到添加的用于认证账号:

[root@linux ~]# cat /etc/nginx/user_passwd admin1:$apr1$Qn57LBlw$fE4QyHrsQReHUrSvPdmxs/admin2:$apr1$VH2Qe1nW$zn.1Hzn3QaF2RwJJDheGN.

重载nginx:

[root@linux ~]# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful[root@linux ~]# nginx -s reload

再次打开个人博客网站管理员登录页面即可显示双重用户认证对话框:

#先进行双重用户验证后即可输入管理员账号密码登录后台

Nginx location优先级详解:

nginx的location配置:

nginx location语法规则:location [=|\~|\~*|^~|/] /uri/ { … }
nginx的location匹配的变量是$uri

符号说明
=表示精确匹配
^~表示uri以指定字符或字符串开头
~表示区分大小写的正则匹配
~*表示不区分大小写的正则匹配
/通用匹配,任何请求都会匹配到

优先级规则:

= 高于 ^~ 高于 ~* 等于 ~ 高于 /

规则示例:

location = "/12.jpg" { ... }
如:
www.test.com/12.jpg 匹配
www.test/abc/12.jpg 不匹配

location ^~ "/abc/" { ... }
如:
www.test/abc/123.html 匹配
www.test.com/a/abc/123.jpg 不匹配

location ~ "png" { ... }
如:
www.test.com/aaa/bbb/ccc/123.png 匹配
www.test.com/aaa/png/123.html 匹配

location ~* "png" { ... }
如:
www.test.com/aaa/bbb/ccc/123.PNG 匹配
www.test.com/aaa/png/123.html 匹配

location /admin/ { ... }
如:
www.test.com/admin/aaa/1.php 匹配
www.test.com/123/admin/1.php 不匹配

对比 / 和 ~
示例1:

server{    listen 80;    server_name www.test.com;    root /tmp/123.com;    location /abc/    {        echo "/";    }    location ~ 'abc'    {        echo "~";    }}

测试命令:curl -x127.0.0.1:80 'www.test.com/abc/1.png'
结果是:~

**对比 ~ 和 ~***
示例2:

server{    listen 80;    server_name www.test.com;    root /tmp/123.com;    location ~ 'abc'    {        echo '~';    }    location ~* 'abc'    {        echo '~*';    }}

测试命令:curl -x127.0.0.1:80 'www.test.com/abc/123.html'
结果是:~

示例3:

server{    listen 80;    server_name www.test.com;    root /tmp/123.com;    location ~* 'abc'    {        echo '~*';    }    location ~ 'abc'    {        echo '~';    }}

测试命令:curl -x127.0.0.1:80 'www.test.com/abc/123.html'
结果是:~*

结论:~ 和 ~*优先级其实是一样的,如果两个同时满足条件,配置文件中哪个location靠前,哪个生效。

对比 ^~ 和 ~
示例4:

server{    listen 80;    server_name www.test.com;    root /tmp/123.com;    location ~ '/abc'    {        echo '~';    }    location ^~ '/abc'    {        echo '^~';    }}

测试命令:curl -x127.0.0.1:80 'www.test.com/abc/123.html
结果是:^~

对比 = 和 ^~
示例5:

server{    listen 80;    server_name www.test.com;    root /tmp/123.com;    location ^~ '/abc.html'    {        echo '^~';    }    location = '/abc.html'    {        echo '=';    }}

测试命令:curl -x127.0.0.1:80 'www.test.com/abc.html
结果是:=


Nginx访问日志主要记录部署在nginx上的网站访问数据,日志格式定义在nginx主配置文件中。

nginx主配置文件:/etc/nginx/nginx.conf

查看nginx主配置文件:

[root@linux ~]# cat /etc/nginx/nginx.conf

下图红框内就是定义的nginx访问日志的格式:

#main:格式名
$remote_addr:访问网站的IP
$remote_user:如果配置了用户认证,表示用户认证的用户名
$time_local:访问时间
$request:http方法,请求的链接,http版本
$status:http状态码
$body_bytes_sent:请求大小
$http_referer:客户端请求时的referer,通俗讲就是该请求是通过哪个链接跳转过来的
$http_user_agent:客户端操作系统和浏览器标识
$http_x_forwarded_for:如果使用了代理,记录代理IP

访问日志配置路径:

针对单个nginx虚拟主机配置访问日志:

1.编辑nginx虚拟主机配置文件:

[root@linux ~]# vi /etc/nginx/conf.d/default.conf

2.定义访问日志存放路径和格式:

3.重载nginx:

[root@linux ~]# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful[root@linux ~]# nginx -s reload

4.在浏览器访问虚拟主机配置的网站后即可生成日志信息:

[root@linux ~]# cat /data/logs/nginx.log 192.168.234.1 - - [15/Oct/2019:14:48:15 +0800] "GET /?p=1 HTTP/1.1" 200 57931 "http://www.blog.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36" "-"192.168.234.1 - - [15/Oct/2019:14:48:15 +0800] "GET /wp-includes/js/comment-reply.min.js?ver=5.2.3 HTTP/1.1" 301 169 "http://www.blog.com/?p=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36" "-"192.168.234.1 - - [15/Oct/2019:14:48:15 +0800] "GET /wp-includes/js/comment-reply.min.js?ver=5.2.3 HTTP/1.1" 200 2234 "http://www.blog.com/?p=1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36" "-"

"如何使用workpress搭建个人博客网站"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

配置 文件 网站 用户 域名 认证 博客 目录 主机 内容 数据 虚拟主机 页面 数据库 登录 密码 管理 验证 信息 命令 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网科技工作委员会 云信互联网科技有限公司 互联网金融监管科技数据 奇酷互联网科技 长亮科技互联网金融 甘肃拓世互联网科技有限公司 玖二柒互联网科技公司待遇 互联网科技寓意 银川新华互联网科技职业技术培训学校图片 宝灵互联网科技有限公司 迪庆互联网科技招生 烟台灵鸽互联网科技有限公司 中科明德北京互联网科技 科技互联网的核心竞争力 中天科技中国工业互联网 互联网营销推广黑科技 东营紫格互联网科技 珠海东科互联网科技有限公司 普陀区互联网教育科技管理办法 瑞安市蟠桃会互联网科技有限公司 手冲咖啡和咖啡机区别 今日互联网科技 智网互联网科技 互联网科技公司有哪些 苏州五指互联网络科技有限 互联网科技大奖都有哪些公司 每天都有哪些好的互联网科技 广州燕处互联网科技有限公司 青岛易易互联网科技 北京品多多互联网科技有限公司
0