CentOS7系統(tǒng)配置Nginx服務(wù)+Apache動(dòng)靜分離(實(shí)戰(zhàn)?。?創(chuàng)新互聯(lián)

Nginx動(dòng)靜分離介紹

  • Nginx的靜態(tài)處理能力很強(qiáng),但是動(dòng)態(tài)處理能力不足,因此,在企業(yè)中常用動(dòng)靜分離技術(shù);

    10年積累的成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有寧都免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
  • 靜態(tài)頁(yè)面交給Nginx處理,動(dòng)態(tài)頁(yè)面交給PHP-FPM模塊或Apache處理;

  • 在Nginx的配置中,是通過(guò)location配置段配合正則匹,配實(shí)現(xiàn)靜態(tài)與動(dòng)態(tài)頁(yè)面的不同處理方式。

搭建LAMP架構(gòu)

為方便實(shí)驗(yàn)直接用yum安裝,不用手工編譯安裝。用兩臺(tái)虛擬機(jī),分別搭建LAMP架構(gòu)和Nginx服務(wù)。

1.安裝Apache服務(wù)

[root@localhost ~]# yum install httpd httpd-devel -y
.........//省略安裝過(guò)程
[root@localhost ~]#

2.開(kāi)啟服務(wù),配置Firewalld防火墻

[root@localhost ~]# systemctl start httpd.service   //開(kāi)啟服務(wù)
[root@localhost ~]# 
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=http  //放通http服務(wù)
success
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=https   //放通https服務(wù)
success
[root@localhost ~]# firewall-cmd --reload    //重載防火墻
success
[root@localhost ~]#

3.安裝mariadb數(shù)據(jù)庫(kù)

MariaDB數(shù)據(jù)庫(kù)管理系統(tǒng)是MySQL的一個(gè)分支,主要由開(kāi)源社區(qū)在維護(hù),采用GPL授權(quán)許可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕松成為MySQL的代替品。

[root@localhost ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y
...........//省略安裝過(guò)程
[root@localhost ~]#

4.開(kāi)啟數(shù)據(jù)庫(kù)服務(wù)

[root@localhost ~]# systemctl start mariadb.service 
[root@localhost ~]#

5.進(jìn)行數(shù)據(jù)庫(kù)設(shè)置

[root@localhost ~]# mysql_secure_installation     //對(duì)數(shù)據(jù)庫(kù)進(jìn)行設(shè)置

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):    //給root管理員設(shè)定密碼,直接回車(chē)
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y   //是否設(shè)置,選擇y
New password:    //輸入新密碼
Re-enter new password:    //再次輸入新密碼
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] n   //是否刪除匿名用戶,選擇n
 ... skipping.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n   //是否拒絕root用戶遠(yuǎn)程登陸,選擇n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n   //是否刪除測(cè)試數(shù)據(jù)庫(kù),選擇n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y   //是否加載權(quán)限列表,選擇y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@localhost ~]#

6.安裝PHP

[root@localhost ~]# yum -y install php
.......//省略過(guò)程
[root@localhost ~]#

7.安裝PHP與MySQL的連接包

[root@localhost ~]# yum install php-mysql -y
........//省略過(guò)程
[root@localhost ~]#

8.安裝PHP插件

[root@localhost ~]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
........//省略過(guò)程
[root@localhost ~]#

9.測(cè)試php首頁(yè)

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# vim index.php
<?php
  phpinfo();
?>
[root@localhost html]#

CentOS7系統(tǒng)配置Nginx服務(wù)+Apache動(dòng)靜分離(實(shí)戰(zhàn)!)

10.測(cè)試完畢,修改主頁(yè)文件

[root@localhost html]# vim /var/www/html/index.php
<?php
 echo "this is apache web!"
?>
[root@localhost html]# systemctl restart httpd.service 
[root@localhost html]#

CentOS7系統(tǒng)配置Nginx服務(wù)+Apache動(dòng)靜分離(實(shí)戰(zhàn)?。?></p><h2>搭建Nginx服務(wù)</h2><h4>1.修改主機(jī)名</h4><pre><code>[root@localhost ~]# hostnamectl set-hostname nginx
[root@localhost ~]# su
[root@nginx ~]#</code></pre><h4>2.解壓nginx源碼包到“/opt/”目錄</h4><pre><code>[root@nginx ~]# mkdir /mnt/tools
[root@nginx ~]# mount.cifs //192.168.100.50/tools /mnt/tools/
Password for root@//192.168.100.50/tools: 
[root@nginx ~]# cd /mnt/tools/LNMP/
[root@nginx LNMP]# ls
Discuz_X3.4_SC_UTF8.zip  mysql-boost-5.7.20.tar.gz  nginx-1.12.2.tar.gz  php-7.1.10.tar.bz2  php-7.1.20.tar.gz
[root@nginx LNMP]# tar zxvf nginx-1.12.2.tar.gz -C /opt/
........//省略過(guò)程
[root@nginx LNMP]#</code></pre><h4>3.安裝環(huán)境包</h4><pre><code>[root@nginx LNMP]# cd /opt/
[root@nginx opt]# ls
nginx-1.12.2  rh
[root@nginx opt]# cd nginx-1.12.2/
[root@nginx nginx-1.12.2]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@nginx nginx-1.12.2]# 
[root@nginx nginx-1.12.2]# yum install -y gcc gcc-c++ pcre-devel zlib-devel
.........//省略過(guò)程
[root@nginx nginx-1.12.2]#</code></pre><h4>3.創(chuàng)建nginx用戶</h4><pre><code>[root@nginx nginx-1.12.2]# useradd -M -s /sbin/nologin nginx
[root@nginx nginx-1.12.2]#</code></pre><h4>4.配置nginx服務(wù),并編譯安裝</h4><pre><code>[root@nginx nginx-1.12.2]# ./configure \   //配置服務(wù)
> --prefix=/usr/local/nginx \   //安裝路徑
> --user=nginx \   //屬主
> --group=nginx \   //數(shù)據(jù)
> --with-http_stub_status_module   //啟用統(tǒng)計(jì)模塊

[root@localhost nginx-1.12.2]# make && make install   //編譯安裝
.........//省略編譯過(guò)程
[root@localhost nginx-1.12.2]#</code></pre><h4>5.優(yōu)化nginx服務(wù)的管理</h4><pre><code>[root@nginx nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/  //優(yōu)化nginx命令路徑
[root@nginx nginx-1.12.2]# 
[root@nginx nginx-1.12.2]# vim /etc/init.d/nginx    //制作nginx管理腳本

#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Service Control Script
PROG=

6.開(kāi)啟nginx服務(wù)

[root@nginx nginx-1.12.2]# service nginx start     //開(kāi)啟服務(wù)
[root@nginx nginx-1.12.2]# netstat -ntap | grep 80   //查看端口
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      58696/nginx: master 
[root@nginx nginx-1.12.2]#
[root@nginx nginx-1.12.2]# systemctl stop firewalld.service    //關(guān)閉防火墻
[root@nginx nginx-1.12.2]# setenforce 0
[root@nginx nginx-1.12.2]#

7.安裝elinks工具測(cè)試nginx網(wǎng)站

[root@nginx nginx-1.12.2]# yum install elinks -y
..........//省略安裝過(guò)程
[root@nginx nginx-1.12.2]#
[root@nginx nginx-1.12.2]# elinks http://192.168.52.132/
[root@nginx nginx-1.12.2]#

CentOS7系統(tǒng)配置Nginx服務(wù)+Apache動(dòng)靜分離(實(shí)戰(zhàn)?。?></p><h4>8.用宿主機(jī)測(cè)試nginx網(wǎng)站</h4><p><img src=

實(shí)現(xiàn)動(dòng)靜分離

1.在nginx服務(wù)配置文件中添加代理

[root@nginx nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.conf
        location ~ \.php$ {
            proxy_pass   http://192.168.52.131;   //代理地址
        }
[root@nginx nginx-1.12.2]# service nginx stop 
[root@nginx nginx-1.12.2]# service nginx start 
[root@nginx nginx-1.12.2]#

2.訪問(wèn)nginx服務(wù)的地址(靜態(tài)資源)

CentOS7系統(tǒng)配置Nginx服務(wù)+Apache動(dòng)靜分離(實(shí)戰(zhàn)?。?></p><h4>3.訪問(wèn)nginx服務(wù)地址(動(dòng)態(tài)資源)</h4><p><img src=高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

當(dāng)前名稱:CentOS7系統(tǒng)配置Nginx服務(wù)+Apache動(dòng)靜分離(實(shí)戰(zhàn)?。?創(chuàng)新互聯(lián)
當(dāng)前網(wǎng)址:http://bm7419.com/article40/dgcdeo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、ChatGPT用戶體驗(yàn)、定制開(kāi)發(fā)、做網(wǎng)站、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化