CentOS7系統(tǒng)配置Nginx服務(wù)+Apache動靜分離(實戰(zhàn)?。?/h1>

Nginx動靜分離介紹

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

    成都一家集口碑和實力的網(wǎng)站建設(shè)服務(wù)商,擁有專業(yè)的企業(yè)建站團(tuán)隊和靠譜的建站技術(shù),十余年企業(yè)及個人網(wǎng)站建設(shè)經(jīng)驗 ,為成都近千家客戶提供網(wǎng)頁設(shè)計制作,網(wǎng)站開發(fā),企業(yè)網(wǎng)站制作建設(shè)等服務(wù),包括成都營銷型網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),同時也為不同行業(yè)的客戶提供成都做網(wǎng)站、成都網(wǎng)站設(shè)計的服務(wù),包括成都電商型網(wǎng)站制作建設(shè),裝修行業(yè)網(wǎng)站制作建設(shè),傳統(tǒng)機械行業(yè)網(wǎng)站建設(shè),傳統(tǒng)農(nóng)業(yè)行業(yè)網(wǎng)站制作建設(shè)。在成都做網(wǎng)站,選網(wǎng)站制作建設(shè)服務(wù)商就選成都創(chuàng)新互聯(lián)公司。

  • 靜態(tài)頁面交給Nginx處理,動態(tài)頁面交給PHP-FPM模塊或Apache處理;

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

搭建LAMP架構(gòu)

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

1.安裝Apache服務(wù)

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

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

[root@localhost ~]# systemctl start httpd.service   //開啟服務(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ù)庫

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

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

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

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

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

[root@localhost ~]# mysql_secure_installation     //對數(shù)據(jù)庫進(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è)定密碼,直接回車
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   //是否刪除測試數(shù)據(jù)庫,選擇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
.......//省略過程
[root@localhost ~]#

7.安裝PHP與MySQL的連接包

[root@localhost ~]# yum install php-mysql -y
........//省略過程
[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
........//省略過程
[root@localhost ~]#

9.測試php首頁

[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動靜分離(實戰(zhàn)?。?></p><h4>10.測試完畢,修改主頁文件</h4><pre><code>[root@localhost html]# vim /var/www/html/index.php
<?php
 echo

CentOS7系統(tǒng)配置Nginx服務(wù)+Apache動靜分離(實戰(zhàn)?。?></p><h2>搭建Nginx服務(wù)</h2><h4>1.修改主機名</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/
........//省略過程
[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
.........//省略過程
[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)計模塊

[root@localhost nginx-1.12.2]# make && make install   //編譯安裝
.........//省略編譯過程
[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.開啟nginx服務(wù)

[root@nginx nginx-1.12.2]# service nginx start     //開啟服務(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工具測試nginx網(wǎng)站

[root@nginx nginx-1.12.2]# yum install elinks -y
..........//省略安裝過程
[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動靜分離(實戰(zhàn)?。?></p><h4>8.用宿主機測試nginx網(wǎng)站</h4><p><img src=CentOS7系統(tǒng)配置Nginx服務(wù)+Apache動靜分離(實戰(zhàn)?。?/a>
當(dāng)前鏈接:http://muchs.cn/article26/ihdpcg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司商城網(wǎng)站、網(wǎng)站排名、服務(wù)器托管、全網(wǎng)營銷推廣、關(guān)鍵詞優(yōu)化

廣告

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

綿陽服務(wù)器托管