91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

實現apache與nginx之間的動靜分離

發布時間:2020-07-22 16:11:10 來源:網絡 閱讀:205 作者:qq5d47f509174fe 欄目:系統運維

實現apache與nginx之間的動靜分離解析

Nginx的靜態處理能力很強,但是動態處理能力不足,因此,在企業中常用動靜分離技術。

針對PHP的動靜分離,靜態頁面交給Nginx處理,動態頁面交給PHP-FPM模塊或Apache處理。

在Nginx的配置中,是通過location配置段配合正則匹配實現靜態與動態頁面的不同處理方式

其簡單示意圖如下:

實現apache與nginx之間的動靜分離

本次實驗將使用兩臺虛擬機,分別模擬LNMP端與NGINX端

首先是LAMP的架設

LAMP端

安裝http服務

[root@localhost ~]# hostnamectl set-hostname LAMP       //更改主機名
[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    //防火墻設定允許通過
success
[root@lamp ~]# firewall-cmd --zone=public --add-service=https --permanent 
success
[root@lamp ~]# firewall-cmd --reload 
success

安裝mariadb數據庫

概述:

MariaDB數據庫管理系統是MySQL的一個分支,主要由開源社區在維護,采用GPL授權許可 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                     //對數據庫進行設置

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):        //回車進行下一步
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                 //是否允許遠程根登錄,選擇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                 //是否進行刷新?(選擇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與數據庫的關系
[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

創建http站點

[root@lamp ~]# cd /var/www/html/          //前往http站點目錄
[root@lamp html]# ll       //此時為空
總用量 0
[root@lamp html]# vim index.php           //新建首頁
添加
<?php
  phpinfo();
?>
[root@lamp html]# systemctl restart httpd.service

此時,使用測試機進行訪問是可以查看到php的動態網頁的,證明LAMP架構成功,下面就是nginx方面的設置。

實現apache與nginx之間的動靜分離

Nginx端

開啟另一臺虛擬機作為nginx端

手工編譯安裝nginx

[root@localhost ~]# hostnamectl set-hostname nginx      //更改主機名
[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     //創建程序性用戶
[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     //編譯安裝

編寫啟動腳本

[root@nginx nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/    //創建軟鏈接方便識別
[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

驗證nginx服務

此時,我們通過測試機進行訪問,即可得到如下界面:

實現apache與nginx之間的動靜分離

但是,若訪問php格式的動態網頁則會出現404訪問錯誤的問題

實現apache與nginx之間的動靜分離

想要解決這個問題,就引入了下面的實驗,在nginx配置文件中進行動靜分離的設置

nginx端

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

至此,動靜分離就全部完成了。

實驗驗證

動態網頁

實現apache與nginx之間的動靜分離

靜態網頁

實現apache與nginx之間的動靜分離

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

华安县| 清涧县| 泸定县| 芒康县| 班戈县| 北海市| 大悟县| 乐平市| 荃湾区| 原阳县| 芒康县| 永济市| 株洲县| 沁源县| 滨海县| 平定县| 嵊州市| 平武县| 曲松县| 固安县| 乌鲁木齐县| 吐鲁番市| 宜州市| 屏东县| 永济市| 乐业县| 阳江市| 鹰潭市| 苍南县| 馆陶县| 高州市| 双城市| 孟村| 保靖县| 肥乡县| 延边| 英超| 乐陵市| 微山县| 彩票| 玉溪市|