真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

實(shí)現(xiàn)apache與nginx之間的動(dòng)靜分離

實(shí)現(xiàn)apache與nginx之間的動(dòng)靜分離解析

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

在金口河等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需定制開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),網(wǎng)絡(luò)營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),金口河網(wǎng)站建設(shè)費(fèi)用合理。

針對PHP的動(dòng)靜分離,靜態(tài)頁面交給Nginx處理,動(dòng)態(tài)頁面交給PHP-FPM模塊或Apache處理。

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

其簡單示意圖如下:

實(shí)現(xiàn)apache與nginx之間的動(dòng)靜分離

本次實(shí)驗(yàn)將使用兩臺虛擬機(jī),分別模擬LNMP端與NGINX端

首先是LAMP的架設(shè)

LAMP端

安裝http服務(wù)

[root@localhost ~]# hostnamectl set-hostname LAMP       //更改主機(jī)名
[root@localhost ~]# su
[root@lamp ~]# yum install httpd httpd-devel -y
[root@lamp ~]# systemctl start httpd.service
[root@lamp ~]# firewall-cmd --zone=public --add-service=http --permanent    //防火墻設(shè)定允許通過
success
[root@lamp ~]# firewall-cmd --zone=public --add-service=https --permanent 
success
[root@lamp ~]# firewall-cmd --reload 
success

安裝mariadb數(shù)據(jù)庫

概述:

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

[root@lamp ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y
[root@lamp ~]# systemctl start mariadb.service 
[root@lamp ~]# 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):        //回車進(jìn)行下一步
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                             //建立新的root管理密碼,選擇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                 //是否允許遠(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        //選擇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                 //是否進(jì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!

安裝PHP工具

[root@lamp ~]# yum -y install php              //安裝PHP工具
[root@lamp ~]# yum install php-mysql -y        //建立php與數(shù)據(jù)庫的關(guān)系
[root@lamp ~]# yum -y install \
php-gd \
php-ldap \
php-odbc \
php-pear \
php-xml \
php-xmlrpc \
php-mbstring \
php-snmp \
php-soap \
curl curl-devel \
php-bcmath

創(chuàng)建http站點(diǎn)

[root@lamp ~]# cd /var/www/html/          //前往http站點(diǎn)目錄
[root@lamp html]# ll       //此時(shí)為空
總用量 0
[root@lamp html]# vim index.php           //新建首頁
添加

[root@lamp html]# systemctl restart httpd.service

此時(shí),使用測試機(jī)進(jìn)行訪問是可以查看到php的動(dòng)態(tài)網(wǎng)頁的,證明LAMP架構(gòu)成功,下面就是nginx方面的設(shè)置。

實(shí)現(xiàn)apache與nginx之間的動(dòng)靜分離

Nginx端

開啟另一臺虛擬機(jī)作為nginx端

手工編譯安裝nginx

[root@localhost ~]# hostnamectl set-hostname nginx      //更改主機(jī)名
[root@localhost ~]# su
[root@nginx mnt]# tar zxvf nginx-1.12.0.tar.gz -C /opt
[root@nginx mnt]# cd /opt/nginx-1.12.0/
[root@nginx nginx-1.12.0]# useradd -M -s /sbin/nologin nginx     //創(chuàng)建程序性用戶
[root@nginx nginx-1.12.0]# yum -y install \
gcc gcc-c++ \
pcre pcre-devel \
zlib-devel \
expat-devel
[root@nginx nginx-1.12.0]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module
[root@nginx nginx-1.12.0]# make && make install     //編譯安裝

編寫啟動(dòng)腳本

[root@nginx nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/    //創(chuàng)建軟鏈接方便識別
[root@nginx nginx-1.12.0]# vim /etc/init.d/nginx
添加
#!/bin/bash
wenjian="/usr/local/nginx/sbin/nginx"
pid="/usr/local/nginx/logs/nginx.pid"
case $1 in
start)
    $wenjian ;;
stop)
    kill -s QUIT $(cat $pid) ;;
restart)
    $0 stop
    $0 start
;;
reload)
    kill -s HUP $(cat $pid) ;;
*)
    echo "Please,try again"
    exit 1 ;;
esac
exit 0
[root@nginx nginx-1.12.0]# chmod +x /etc/init.d/nginx
[root@nginx init.d]# service nginx start 
[root@nginx init.d]# netstat -atnp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      8638/nginx: master
[root@nginx init.d]# systemctl stop firewalld.service 
[root@nginx init.d]# setenforce 0

驗(yàn)證nginx服務(wù)

此時(shí),我們通過測試機(jī)進(jìn)行訪問,即可得到如下界面:

實(shí)現(xiàn)apache與nginx之間的動(dòng)靜分離

但是,若訪問php格式的動(dòng)態(tài)網(wǎng)頁則會出現(xiàn)404訪問錯(cuò)誤的問題

實(shí)現(xiàn)apache與nginx之間的動(dòng)靜分離

想要解決這個(gè)問題,就引入了下面的實(shí)驗(yàn),在nginx配置文件中進(jìn)行動(dòng)靜分離的設(shè)置

nginx端

[root@nginx init.d]# cd /usr/local/nginx/conf
[root@nginx conf]# vim nginx.conf     //修改配置文件
59到61行,取消注釋,并按照下面進(jìn)行修改
  location ~ \.php$ {
        proxy_pass   http://192.168.142.128;    #apache服務(wù)器所在地址
  }
wq保存退出
[root@nginx nginx]# service nginx stop       //重啟服務(wù)
[root@nginx nginx]# service nginx start

至此,動(dòng)靜分離就全部完成了。

實(shí)驗(yàn)驗(yàn)證

動(dòng)態(tài)網(wǎng)頁

實(shí)現(xiàn)apache與nginx之間的動(dòng)靜分離

靜態(tài)網(wǎng)頁

實(shí)現(xiàn)apache與nginx之間的動(dòng)靜分離


新聞名稱:實(shí)現(xiàn)apache與nginx之間的動(dòng)靜分離
當(dāng)前網(wǎng)址:http://weahome.cn/article/jhsoie.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部