在一臺云服務(wù)器上利用Nginx搭建多個WordPress網(wǎng)站教程(超級詳細(xì))

實驗準(zhǔn)備

一臺騰訊云服務(wù)器
二個域名(IP與域名已經(jīng)建立解析關(guān)系)
Linux關(guān)于web架構(gòu)的知識

實驗步驟

1.用crt遠(yuǎn)程登錄騰訊云服務(wù)器

image

2.安裝nginx从绘,mysql寄疏,php

建議使用lnmp一鍵安裝包安裝,方便快捷

獲取lnmp一鍵安裝包鏈接

lnpm官網(wǎng)鏈接

找到下載頁面選擇最新的復(fù)制其鏈接僵井。

寫此文時最新版本信息如下:

LNMP 1.4 測試版
http://soft.vpser.net/lnmp/lnmp1.4beta.tar.gz  (131KB)

安裝 163源

[root@linfan ~]# cd /etc/yum.repos.d/
[root@linfan yum.repos.d]# mv * /tmp/
[root@linfan yum.repos.d]# curl -o 163.repo   http://mirrors.163.com/.help/CentOS7-Base-163.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1572  100  1572    0     0  13343      0 --:--:-- --:--:-- --:--:-- 13435
[root@linfan yum.repos.d]# sed -i 's/\$releasever/7/g' 163.repo
[root@linfan yum.repos.d]# sed -i 's/^enabled=.*/enabled=1/g' 163.repo
[root@linfan yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base centosplus extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
[root@linfan yum.repos.d]# yum -y install epel-release
Loaded plugins: fastestmirror
base                                                                                               | 3.6 kB  00:00:00
centosplus                                                                                         | 3.4 kB  00:00:00
extras                                                                                             | 3.4 kB  00:00:00
updates                                                                                            | 3.4 kB  00:00:00
(1/5): base/x86_64/group_gz                                                                        | 166 kB  00:00:00
(2/5): extras/x86_64/primary_db                                                                    | 187 kB  00:00:00
(3/5): centosplus/x86_64/primary_db                                                                | 2.9 MB  00:00:01
(4/5): updates/x86_64/primary_db                                                                   | 5.2 MB  00:00:02
(5/5): base/x86_64/primary_db                                                                      | 5.9 MB  00:00:02
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================
 Package                          Arch                       Version                     Repository                  Size
==========================================================================================================================
Installing:
 epel-release                     noarch                     7-11                        extras                      15 k

Transaction Summary
==========================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
warning: /var/cache/yum/x86_64/7/extras/packages/epel-release-7-11.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for epel-release-7-11.noarch.rpm is not installed
epel-release-7-11.noarch.rpm                                                                       |  15 kB  00:00:00
Retrieving key from http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 From       : http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                                               1/1
  Verifying  : epel-release-7-11.noarch                                                                               1/1

Installed:
  epel-release.noarch 0:7-11

Complete!
[root@linfan ~]# yum -y install wget 

上傳腳本并執(zhí)行

// 腳本執(zhí)行過程中 有需要選擇的直接敲回車鍵即可 有選擇版本的需要根據(jù)自己的需求來選擇即可
[root@linfan ~]# wget http://soft.vpser.net/lnmp/lnmp1.4beta.tar.gz 

[root@linfan ~]# tar -zxvf lnmp1.4beta.tar.gz 
[root@linfan ~]# cd lnmp1.4
[root@linfan lnmp1.4]# ./install.sh   

+------------------------------------------------------------------------+
|          LNMP V1.4 for CentOS Linux Server, Written by Licess          |
+------------------------------------------------------------------------+
|        A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux       |
+------------------------------------------------------------------------+
|           For more information please visit https://lnmp.org           |
+------------------------------------------------------------------------+
You have 5 options for your DataBase install.
1: Install MySQL 5.1.73
2: Install MySQL 5.5.56 (Default)
3: Install MySQL 5.6.36
4: Install MySQL 5.7.18
5: Install MariaDB 5.5.56
6: Install MariaDB 10.0.30
7: Install MariaDB 10.1.23
0: DO NOT Install MySQL/MariaDB
Enter your choice (1, 2, 3, 4, 5, 6, 7 or 0):  
Enter your choice (1, 2, 3, 4, 5, 6, 7 or 0):
No input,You will install MySQL 5.5.56
===========================
Please setup root password of MySQL.(Default password: root)
Please enter:
MySQL root password: root
===========================
Do you want to enable or disable the InnoDB Storage Engine?
Default enable,Enter your choice [Y/n]:
No input,The InnoDB Storage Engine will enable.
===========================
You have 6 options for your PHP install.
1: Install PHP 5.2.17
2: Install PHP 5.3.29
3: Install PHP 5.4.45
4: Install PHP 5.5.38 (Default)
5: Install PHP 5.6.31
6: Install PHP 7.0.21
7: Install PHP 7.1.7
Enter your choice (1, 2, 3, 4, 5, 6 or 7):
No input,You will install PHP 5.5.38
===========================
You have 3 options for your Memory Allocator install.
1: Don't install Memory Allocator. (Default)
2: Install Jemalloc
3: Install TCMalloc
Enter your choice (1, 2 or 3):  
No input,You will not install Memory Allocator.

Press any key to install...or Press Ctrl+c to cancel 
//后續(xù)執(zhí)行的過程有些漫長大概三十到四十分鐘左右剖效,可以先看看電視聽聽音樂放松下 哈哈

看到這個界面說明腳本執(zhí)行成功了

image

簡單說明一下,此安裝過程安裝完成便也啟動了nginx塘安,mysql链烈,php-fpm并加入了開機(jī)啟動項。如果重啟服務(wù)器驻债,不需要再單獨手動開啟相關(guān)的服務(wù)了乳规。總的來說相當(dāng)方便的合呐。

此時 在瀏覽器輸入IP即可訪問到如下頁面

image

網(wǎng)站根目錄路徑/home/wwwroot/default,如果只用來放一些靜態(tài)頁面暮的,那么,現(xiàn)在就足夠了淌实,直接將你的html冻辩,js,css等文件丟進(jìn)去即可拆祈。

退出使用ctrl+c

IP與網(wǎng)站的映射關(guān)系

 [root@linfan ~]# vi /usr/local/nginx/conf/nginx.conf
 ...
 ...
  server
    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name lin.kjsc366.com; //編輯此處
        index index.html index.htm index.php;
        root  /home/wwwroot/default;

檢測nginx配置文件語法并重新加載nginx

[root@linfan ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@linfan ~]# nginx -s reload

安裝WordPress

中文官方站點 英文官方站點具體的根據(jù)自己的需求選擇恨闪。下面以中文版為例。當(dāng)前最新版本是4.7.2

為了方便放坏,我們還是在用站點默認(rèn)的路徑

[root@linfan ~]# cd /home/wwwroot/  //進(jìn)入網(wǎng)站根目錄上一級目錄
[root@linfan wwwroot]# mv default old  //將default重命名為old
[root@linfan wwwroot]# wget https://cn.wordpress.org/wordpress-4.7.2-zh_CN.tar.gz  //下載WordPress包中文版
[root@linfan wwwroot]# tar -zxvf wordpress-4.7.2-zh_CN.tar.gz  //解壓WordPress包
[root@linfan wwwroot]# ls
old  wordpress  wordpress-4.7.2-zh_CN.tar.gz
[root@linfan wwwroot]# mv wordpress default  //將wordpress重命名為default
[root@linfan wwwroot]# ls
default  old  wordpress-4.7.2-zh_CN.tar.gz 

給予相應(yīng)權(quán)限

[root@linfan default]# chown -R 755 /home/wwwroot //目錄以及目錄下的文件授權(quán)
chown: changing ownership of ‘/home/wwwroot/old/.user.ini’: Operation not permitted
[root@linfan default]#  chown -R www:www /home/wwwroot/ //將目錄的所有者分給www組下的www用戶咙咽。
chown: changing ownership of ‘/home/wwwroot/old/.user.ini’: Operation not permitted

出現(xiàn)的提示大概是說有一個文件無法更改用戶分組和權(quán)限。不會影響你的wordpress淤年,忽略就好

創(chuàng)建一個數(shù)據(jù)庫wordpress

[root@linfan default]# mysql -u root -p
Enter password:  密碼默認(rèn)是root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 5.5.56-log Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+
4 rows in set (0.00 sec)

mysql> quit  

配置WordPress

在瀏覽器輸入域名地址進(jìn)行訪問

image

點擊現(xiàn)在就開始钧敞。這時候我們看到如下頁面:

image

按照之前設(shè)置的蜡豹,輸入如下信息:

數(shù)據(jù)庫名:wordpress
用戶名:root
密碼:root
數(shù)據(jù)庫主機(jī):localhost
表前綴:wp_

點擊提交

image

到這一步,基本上就意味著大功告成了犁享,因為后邊基本不會出錯啦余素。

點擊進(jìn)行安裝按鈕。出現(xiàn)下圖:

image

按照自己的需求填寫炊昆,比如我這里填寫如下:

image

點擊安裝WordPress按鈕桨吊,然后登錄設(shè)置啥的純頁面操作就不在這里過多介紹

image

再建一個WordPress

在網(wǎng)站根網(wǎng)頁目錄下創(chuàng)建一個新的目錄/home/wwwroot/default/doudou

[root@linfan wwwroot]# tar xf wordpress-4.7.2-zh_CN.tar.gz
[root@linfan wwwroot]# ls
default  old  wordpress  wordpress-4.7.2-zh_CN.tar.gz
[root@linfan wwwroot]# mv wordpress default/doudou
[root@linfan wwwroot]# cd default/doudou
[root@linfan doudou]# ls
index.php    wp-activate.php     wp-comments-post.php  wp-cron.php        wp-load.php   wp-settings.php   xmlrpc.php
license.txt  wp-admin            wp-config-sample.php  wp-includes        wp-login.php  wp-signup.php
readme.html  wp-blog-header.php  wp-content            wp-links-opml.php  wp-mail.php   wp-trackback.php

復(fù)制配置文件里面的server內(nèi)容 在后面添加復(fù)制的內(nèi)容

[root@linfan ~]# vi /usr/local/nginx/conf/nginx.conf
...
...
   server
    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name fan.kjsc366.com; //編輯此處
        index index.html index.htm index.php;
        root  /home/wwwroot/default/doudou; //編輯此處添加上一步創(chuàng)建的目錄doudou

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d; 
        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }   
  include vhost/*.conf; 
  }    

新建一個同名的vhost/doudou.confinclude vhost/*.conf建立對應(yīng)關(guān)系

[root@linfan ~]mkdir -p /vhost/doudou.conf

再建立一個數(shù)據(jù)庫doudou

[root@linfan ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.5.56-log Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database doudou;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| doudou             |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+
5 rows in set (0.00 sec)

mysql> quit
Bye

輸入fan.kjsc366.com

image

重新出來一個wordpress頁面

image

此時 我使用新建的數(shù)據(jù)庫doudou 進(jìn)行配置WordPress

上面有詳細(xì)配置過程,在此不再贅述

我們來直接看效果:
輸入域名lin.kjsc366.com 效果如下:

image

輸入域名fan.kjsc366.com 效果如下

image

PS:

后期如果需要配置WordPress 則需要在瀏覽器輸入域名/wp-admin/setup-config.php
例如我的是

lin.kjsc366.com/wp-admin/setup-config.php

后期問題解決

有問題的反饋在此凤巨,我會進(jìn)行補(bǔ)充视乐。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市敢茁,隨后出現(xiàn)的幾起案子佑淀,更是在濱河造成了極大的恐慌,老刑警劉巖彰檬,帶你破解...
    沈念sama閱讀 219,427評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件伸刃,死亡現(xiàn)場離奇詭異,居然都是意外死亡逢倍,警方通過查閱死者的電腦和手機(jī)捧颅,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來较雕,“玉大人碉哑,你說我怎么就攤上這事×两” “怎么了扣典?”我有些...
    開封第一講書人閱讀 165,747評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長慎玖。 經(jīng)常有香客問我贮尖,道長,這世上最難降的妖魔是什么趁怔? 我笑而不...
    開封第一講書人閱讀 58,939評論 1 295
  • 正文 為了忘掉前任远舅,我火速辦了婚禮,結(jié)果婚禮上痕钢,老公的妹妹穿的比我還像新娘。我一直安慰自己序六,他們只是感情好任连,可當(dāng)我...
    茶點故事閱讀 67,955評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著例诀,像睡著了一般随抠。 火紅的嫁衣襯著肌膚如雪裁着。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,737評論 1 305
  • 那天拱她,我揣著相機(jī)與錄音二驰,去河邊找鬼。 笑死秉沼,一個胖子當(dāng)著我的面吹牛桶雀,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播唬复,決...
    沈念sama閱讀 40,448評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼矗积,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了敞咧?” 一聲冷哼從身側(cè)響起棘捣,我...
    開封第一講書人閱讀 39,352評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎休建,沒想到半個月后乍恐,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,834評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡测砂,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,992評論 3 338
  • 正文 我和宋清朗相戀三年茵烈,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片邑彪。...
    茶點故事閱讀 40,133評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡瞧毙,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出寄症,到底是詐尸還是另有隱情宙彪,我是刑警寧澤,帶...
    沈念sama閱讀 35,815評論 5 346
  • 正文 年R本政府宣布有巧,位于F島的核電站释漆,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏篮迎。R本人自食惡果不足惜男图,卻給世界環(huán)境...
    茶點故事閱讀 41,477評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望甜橱。 院中可真熱鬧逊笆,春花似錦、人聲如沸岂傲。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至乃戈,卻和暖如春褂痰,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背症虑。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評論 1 272
  • 我被黑心中介騙來泰國打工缩歪, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留匪蝙,地道東北人韵卤。 一個月前我還...
    沈念sama閱讀 48,398評論 3 373
  • 正文 我出身青樓骗污,卻偏偏與公主長得像,于是被迫代替她去往敵國和親沈条。 傳聞我的和親對象是個殘疾皇子需忿,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,077評論 2 355

推薦閱讀更多精彩內(nèi)容