本篇內(nèi)容介紹了“如何使用workpress搭建個(gè)人博客網(wǎng)站”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)建站專(zhuān)注于企業(yè)全網(wǎng)營(yíng)銷(xiāo)推廣、網(wǎng)站重做改版、北票網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5場(chǎng)景定制、商城開(kāi)發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為北票等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。
前面幾篇文章已經(jīng)介紹了怎么在Linux下搭建LNMP環(huán)境:
1.安裝MySQL/MariaDB
2.安裝PHP
3.安裝Nginx
4.nginx配置虛擬主機(jī)
接下來(lái)開(kāi)始使用workpress搭建個(gè)人博客網(wǎng)站:
workpress官網(wǎng):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
創(chuàng)建博客網(wǎng)站目錄:
[root@linux ~]# mkdir -p /data/www/test.blog.com
將workpress安裝包中的文件移動(dòng)到博客網(wǎng)站目錄下:
[root@linux ~]# mv wordpress/* /data/www/test.blog.com/
修改nginx虛擬主機(jī)配置文件:
[root@linux ~]# vi /etc/nginx/conf.d/default.conf
修改以下內(nèi)容:
1.定義博客網(wǎng)站的自定義域名(如有真實(shí)域名可以使用真實(shí)域名)
2.定義博客網(wǎng)站的目錄
3.添加index.php(WordPress使用的是php)
4.將該配置文件底部的php段內(nèi)容的注釋符號(hào)#去掉,定義網(wǎng)站的目錄
5.修改/scripts為網(wǎng)站目錄路徑
驗(yàn)證配置文件并重載:
[root@linux ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@linux ~]# nginx -s reload
Windows上修改hosts文件內(nèi)容為:
打開(kāi)瀏覽器訪問(wèn)test.blog.com:
#wordpress的頁(yè)面已成功顯示
接下來(lái)創(chuàng)建博客網(wǎng)站的數(shù)據(jù)庫(kù):
登錄:
[root@linux ~]# mysql -uroot -p123456 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 12 Server version: 10.3.18-MariaDB MariaDB Server Copyright (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)]>
創(chuàng)建數(shù)據(jù)庫(kù):
MariaDB [(none)]> create database wordpress; Query OK, 1 row affected (0.000 sec)
創(chuàng)建用戶:
MariaDB [(none)]> grant all on wordpress.* to 'blog'@'127.0.0.1' identified by 'test123'; Query OK, 0 rows affected (0.029 sec)
#創(chuàng)建用戶blog,密碼test123,授權(quán)從127.0.0.1連接
修改網(wǎng)站目錄文件的屬主:
[root@linux ~]# cd /data/www/test.blog.com/ [root@linux test.blog.com]# chown -R php-fpm .
打開(kāi)瀏覽器訪問(wèn)test.blog.com開(kāi)始配置數(shù)據(jù)庫(kù)信息:
#輸入好數(shù)據(jù)庫(kù)信息點(diǎn)擊提交即可
開(kāi)始安裝:
#定義網(wǎng)站標(biāo)題,用戶名,密碼(郵件地址必填,但未配置郵件服務(wù)不會(huì)發(fā)郵件)
填寫(xiě)完成后點(diǎn)擊安裝,顯示成功:
再次訪問(wèn)自定義的域名test.blog.com即可顯示出博客頁(yè)面:
在頁(yè)面下方點(diǎn)擊登錄后進(jìn)入后臺(tái)管理頁(yè)面:
接下來(lái)就可以自由編輯博客的主頁(yè)排版、外觀樣式、權(quán)限等設(shè)置了。
discuz官網(wǎng):https://www.discuz.net/forum.php
安裝git:
[root@linux ~]# yum -y install git
通過(guò)git的方式克隆discuz包到本機(jī):
[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虛擬主機(jī)配置文件:
[root@linux ~]# cd /etc/nginx/conf.d/ [root@linux conf.d]# cp default.conf bbs.conf
編輯配置文件:
[root@linux conf.d]# vi bbs.conf
修改以下內(nèi)容:
1.定義bbs網(wǎng)站的自定義域名(如有真實(shí)域名可以使用真實(shí)域名)
2.定義bbs網(wǎng)站的目錄
3.添加index.php(discuz使用的是php)
4.將該配置文件底部的php段內(nèi)容的注釋符號(hào)#去掉,定義bbs網(wǎng)站的目錄
5.修改/scripts為bbs網(wǎng)站目錄路徑
驗(yàn)證配置文件并重載:
[root@linux conf.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: 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系統(tǒng)C:\Windows\System32\drivers\etc\hosts文件:(使用真實(shí)域名并已解析到服務(wù)器IP地址可忽略此步)
#添加自定義域名:test.bbs.com
打開(kāi)瀏覽器訪問(wèn)域名即可開(kāi)始安裝:
點(diǎn)擊我同意之后繼續(xù)點(diǎn)擊下一步需要配置數(shù)據(jù)庫(kù)信息:
登錄數(shù)據(jù)庫(kù):
[root@linux test.bbs.com]# mysql -uroot -p123456 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 92 Server version: 10.3.18-MariaDB MariaDB Server Copyright (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)]>
創(chuàng)建bbs網(wǎng)站數(shù)據(jù)庫(kù):
MariaDB [(none)]> create database bbs; Query OK, 1 row affected (0.000 sec)
創(chuàng)建授權(quán)用戶:
MariaDB [(none)]> grant all on bbs.* to 'bbsuser'@'127.0.0.1' identified by 'test123'; Query OK, 0 rows affected (0.005 sec)
#創(chuàng)建用戶bbsuser,密碼test123,授權(quán)從127.0.0.1連接
填寫(xiě)數(shù)據(jù)庫(kù)信息:
#數(shù)據(jù)庫(kù)信息填寫(xiě)剛創(chuàng)建的,管理員信息自己設(shè)置密碼即可,郵箱默認(rèn)即可
完成安裝后bbs網(wǎng)站就搭建完成:
使用管理員賬號(hào)登錄后臺(tái):
接下來(lái)即可開(kāi)始自由設(shè)置bbs網(wǎng)站了!
--------------------------------------------------------------------------------------------------
nginx配置多個(gè)域名:
編輯nginx虛擬主機(jī)配置文件:
[root@linux ~]# vi /etc/nginx/conf.d/default.conf
在server_name項(xiàng)新增域名www.blog.com:
驗(yàn)證配置并重載:
[root@linux ~]# nginx -t && nginx -s reload
接下來(lái)即可通過(guò)新域名www.blog.com訪問(wèn)該網(wǎng)站:
nginx配置域名重定向/跳轉(zhuǎn):
編輯nginx虛擬主機(jī)配置文件:
[root@linux ~]# vi /etc/nginx/conf.d/default.conf
添加如下內(nèi)容:
if ( $host = test.blog.com ) { rewrite /(.*) http://www.blog.com/$1 permanent; }
驗(yàn)證配置并重載:
[root@linux ~]# nginx -t && nginx -s reload nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
測(cè)試:
[root@linux ~]# curl -x127.0.0.1:80 -I test.blog.com HTTP/1.1 301 Moved Permanently Server: nginx/1.16.1 Date: Sun, 13 Oct 2019 15:24:43 GMT Content-Type: text/html Content-Length: 169 Connection: keep-alive Location: http://www.blog.com/
#http狀態(tài)碼301,Location: http://www.blog.com/,對(duì)test.blog.com的請(qǐng)求已成功跳轉(zhuǎn)到www.blog.com,對(duì)于搜索引擎來(lái)說(shuō),test.blog.com被認(rèn)為是舊域名,而優(yōu)先訪問(wèn)新域名www.blog.com
永久重定向:permanent http狀態(tài)碼:301 (域名重定向使用,轉(zhuǎn)移域名權(quán)重)
臨時(shí)重定向:redirect http狀態(tài)碼:302 (非域名跳轉(zhuǎn)使用,比如文件跳轉(zhuǎn))
編輯nginx虛擬主機(jī)配置文件:
[root@linux ~]# vi /etc/nginx/conf.d/default.conf
nginx添加文件跳轉(zhuǎn):
rewrite /1.txt /2.txt redirect;
驗(yàn)證配置并重載:
[root@linux ~]# nginx -t && nginx -s reload nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
測(cè)試:
[root@linux ~]# curl -x127.0.0.1:80 -I www.blog.com/1.txt HTTP/1.1 302 Moved Temporarily Server: nginx/1.16.1 Date: Sun, 13 Oct 2019 15:45:17 GMT Content-Type: text/html Content-Length: 145 Location: http://www.blog.com/2.txt Connection: keep-alive
#http狀態(tài)碼:302,Location: http://www.blog.com/2.txt,文件跳轉(zhuǎn)成功
Nginx雙重用戶認(rèn)證:
適用于一些網(wǎng)站的重要頁(yè)面(比如:管理員登錄的后臺(tái)管理頁(yè)面),雙重認(rèn)證的效果就是在打開(kāi)重要頁(yè)面輸入賬號(hào)密碼登錄之前先驗(yàn)證一次用戶雙重認(rèn)證的用戶名和密碼。
打開(kāi)個(gè)人博客網(wǎng)站管理員登錄頁(yè)面:
修改nginx虛擬主機(jī)配置文件給當(dāng)前頁(yè)面wp-login.php添加雙重用戶認(rèn)證:
[root@linux ~]# vi /etc/nginx/conf.d/default.conf
添加以下內(nèi)容:
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項(xiàng)的location去掉,使之變?yōu)槿峙渲茫?br/>
由于添加的配置內(nèi)容定義了雙重用戶驗(yàn)證配置為/etc/ngninx/user_passwd,但當(dāng)前沒(méi)有這個(gè)文件,需要使用htpasswd命令生成該文件:
安裝httpd-tools包:
[root@linux ~]# yum -y install httpd-tools
生成配置文件并添加認(rèn)證用戶:
[root@linux ~]# htpasswd -c /etc/nginx/user_passwd admin1 New password: Re-type new password: Adding password for user admin1
#生成user_passwd文件并增加認(rèn)證用戶admin1并設(shè)置密碼,-c 參數(shù):創(chuàng)建,首次生成認(rèn)證配置文件使用
需要新增認(rèn)證用戶使用-m 參數(shù)(MD5加密):
[root@linux ~]# htpasswd -m /etc/nginx/user_passwd admin2 New password: Re-type new password: Adding password for user admin2
查看用戶認(rèn)證配置文件即可看到添加的用于認(rèn)證賬號(hào):
[root@linux ~]# cat /etc/nginx/user_passwd admin1:$apr1$Qn57LBlw$fE4QyHrsQReHUrSvPdmxs/ admin2:$apr1$VH2Qe1nW$zn.1Hzn3QaF2RwJJDheGN.
重載nginx:
[root@linux ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@linux ~]# nginx -s reload
再次打開(kāi)個(gè)人博客網(wǎng)站管理員登錄頁(yè)面即可顯示雙重用戶認(rèn)證對(duì)話框:
#先進(jìn)行雙重用戶驗(yàn)證后即可輸入管理員賬號(hào)密碼登錄后臺(tái)
Nginx location優(yōu)先級(jí)詳解:
nginx的location配置:
nginx location語(yǔ)法規(guī)則:location [=|\~|\~*|^~|/] /uri/ { … }
nginx的location匹配的變量是$uri
符號(hào) | 說(shuō)明 |
---|---|
= | 表示精確匹配 |
^~ | 表示uri以指定字符或字符串開(kāi)頭 |
~ | 表示區(qū)分大小寫(xiě)的正則匹配 |
~* | 表示不區(qū)分大小寫(xiě)的正則匹配 |
/ | 通用匹配,任何請(qǐng)求都會(huì)匹配到 |
優(yōu)先級(jí)規(guī)則:
= 高于 ^~ 高于 ~* 等于 ~ 高于 /
規(guī)則示例:
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 不匹配
對(duì)比 / 和 ~
示例1:
server{ listen 80; server_name www.test.com; root /tmp/123.com; location /abc/ { echo "/"; } location ~ 'abc' { echo "~"; } }
測(cè)試命令:curl -x127.0.0.1:80 'www.test.com/abc/1.png'
結(jié)果是:~
**對(duì)比 ~ 和 ~***
示例2:
server { listen 80; server_name www.test.com; root /tmp/123.com; location ~ 'abc' { echo '~'; } location ~* 'abc' { echo '~*'; } }
測(cè)試命令:curl -x127.0.0.1:80 'www.test.com/abc/123.html'
結(jié)果是:~
示例3:
server { listen 80; server_name www.test.com; root /tmp/123.com; location ~* 'abc' { echo '~*'; } location ~ 'abc' { echo '~'; } }
測(cè)試命令:curl -x127.0.0.1:80 'www.test.com/abc/123.html'
結(jié)果是:~*
結(jié)論:~ 和 ~*優(yōu)先級(jí)其實(shí)是一樣的,如果兩個(gè)同時(shí)滿足條件,配置文件中哪個(gè)location靠前,哪個(gè)生效。
對(duì)比 ^~ 和 ~
示例4:
server { listen 80; server_name www.test.com; root /tmp/123.com; location ~ '/abc' { echo '~'; } location ^~ '/abc' { echo '^~'; } }
測(cè)試命令:curl -x127.0.0.1:80 'www.test.com/abc/123.html
結(jié)果是:^~
對(duì)比 = 和 ^~
示例5:
server { listen 80; server_name www.test.com; root /tmp/123.com; location ^~ '/abc.html' { echo '^~'; } location = '/abc.html' { echo '='; } }
測(cè)試命令:curl -x127.0.0.1:80 'www.test.com/abc.html
結(jié)果是:=
Nginx訪問(wèn)日志主要記錄部署在nginx上的網(wǎng)站訪問(wèn)數(shù)據(jù),日志格式定義在nginx主配置文件中。
nginx主配置文件:/etc/nginx/nginx.conf
查看nginx主配置文件:
[root@linux ~]# cat /etc/nginx/nginx.conf
下圖紅框內(nèi)就是定義的nginx訪問(wèn)日志的格式:
#main:格式名
$remote_addr:訪問(wèn)網(wǎng)站的IP
$remote_user:如果配置了用戶認(rèn)證,表示用戶認(rèn)證的用戶名
$time_local:訪問(wèn)時(shí)間
$request:http方法,請(qǐng)求的鏈接,http版本
$status:http狀態(tài)碼
$body_bytes_sent:請(qǐng)求大小
$http_referer:客戶端請(qǐng)求時(shí)的referer,通俗講就是該請(qǐng)求是通過(guò)哪個(gè)鏈接跳轉(zhuǎn)過(guò)來(lái)的
$http_user_agent:客戶端操作系統(tǒng)和瀏覽器標(biāo)識(shí)
$http_x_forwarded_for:如果使用了代理,記錄代理IP
訪問(wèn)日志配置路徑:
針對(duì)單個(gè)nginx虛擬主機(jī)配置訪問(wèn)日志:
1.編輯nginx虛擬主機(jī)配置文件:
[root@linux ~]# vi /etc/nginx/conf.d/default.conf
2.定義訪問(wèn)日志存放路徑和格式:
3.重載nginx:
[root@linux ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@linux ~]# nginx -s reload
4.在瀏覽器訪問(wèn)虛擬主機(jī)配置的網(wǎng)站后即可生成日志信息:
[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搭建個(gè)人博客網(wǎng)站”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!