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

溫馨提示×

溫馨提示×

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

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

部署Nginx+Apache動靜分離(實戰!可跟做!)

發布時間:2020-06-07 13:03:32 來源:網絡 閱讀:11161 作者:JarryZ 欄目:系統運維

Nginx動靜分離介紹

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

靜態頁面交給Nginx處理

動態頁面交給PHP+FPM模塊或Apache處理

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

反向代理原理

1.Nginx不僅能作為Web服務器,還具有反向代理、負載均衡和緩存的功能
2.Nginx通過proxy模塊實現將客戶端的請求代理至,上游服務器,此時nginx與.上游服務器的連接是通過http協議進行的
3.Nginx在實現反向代理功能時的最重要指令為proxy_pass, 它能夠并能夠根據URI、客戶端參數或其它的處理邏輯將用戶請求調度至,上游服務器

配置Nginx實現動靜分離

1.本案例根據企業需要,將配置Nginx實現動靜分離,對php頁面的請求轉發給LAMP處理,而靜態頁面交給Nginx處理,以實現動靜分離

2.架構如圖所示:

部署Nginx+Apache動靜分離(實戰!可跟做!)

配置步驟:

1.配置Nginx處理動態頁面請求,在server{};中加入
2.在Apache.工作目錄新建test.php
3.重啟Nginx并測試

[root@nginx php5]#vim /usr/local/httpd/conf/nginx.conf
  server {
  .....
  location ~ \.php$ {
        proxy_pass http://192.168.9.237:8080;
......                                          //LAMP的IP地址

Demo:

環境準備:兩臺CentOS 7,其中7-3做為lamp,7-4做為nginx
第一步:安裝httpd
[root@localhost ~]# yum install httpd httpd-devel -y
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=https
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# systemctl start httpd
此時可以使用宿主機訪問Apache的主頁如下圖所示:

部署Nginx+Apache動靜分離(實戰!可跟做!)

第二步:安裝mariadb數據庫(快捷輕量化的數據庫)
[root@lamp ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y
[root@lamp ~]# systemctl start mariadb
[root@lamp ~]# systemctl start mariadb
[root@lamp ~]# netstat -ntap | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*       LISTEN      16836/mysqld    
[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):       //給root管理員設定密碼,直接回車  
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      //是否設置,選擇yes
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     //是否刪除匿名用戶,選擇no
 ... 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用戶遠程登陸,選擇no
 ... 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      //是否刪除測試數據庫,選擇no
 ... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y        //是否加載權限列表,選擇yes
 ... 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 install php -y 
[root@lamp ~]# yum install php-mysql -y
[root@lamp ~]# 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@lamp ~]# cd /var/www/html/
[root@lamp html]# ls
[root@lamp html]# vim index.php
<?php
  phpinfo();
?>
輸入:wq保存退出
[root@lamp html]# systemctl restart httpd.service
這時在宿主機的瀏覽器中輸入地址:http://192.168.18.128/index.php,就可以訪問到lamp的php主頁

部署Nginx+Apache動靜分離(實戰!可跟做!)

測試準備:
[root@lamp html]# vim index.php
<?php
  echo "apache web !"
?>
輸入:wq保存退出
此時 http://192.168.18.128/index.php 這個地址上顯示的內容如下:

部署Nginx+Apache動靜分離(實戰!可跟做!)

Nginx上的操作:
[root@nginx ~]# mkdir /aaa
[root@nginx ~]# mount.cifs //192.168.10.193/rpm /aaa
Password for root@//192.168.10.193/rpm:  
[root@nginx ~]# cd /aaa
[root@nginx aaa]# ls
apr-1.6.2.tar.gz                  error.png                  nginx-1.12.2.tar.gz
apr-util-1.6.0.tar.gz             httpd-2.4.29.tar.bz2       php-7.1.10.tar.bz2
awstats-7.6.tar.gz                lf.jpg                     php-7.1.20.tar.gz
cronolog-1.6.2-14.el7.x86_64.rpm  mysql-5.6.26.tar.gz
Discuz_X3.4_SC_UTF8.zip           mysql-boost-5.7.20.tar.gz
[root@nginx aaa]# tar zxvf nginx-1.12.2.tar.gz -C /opt/ 
[root@nginx aaa]# 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]# useradd -M -s /sbin/nologin nginx
[root@nginx nginx-1.12.2]# yum install gcc gcc-c++ pcre-devel zlib-devel -y
[root@nginx nginx-1.12.2]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
[root@nginx nginx-1.12.2]# make && make install
[root@nginx nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@nginx nginx-1.12.2]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
  start)
    $PROG
    ;;
  stop)
    kill -s QUIT $(cat $PIDF)
    ;;  
  restart)
    $0 stop
    $0 start
    ;;  
  reload)
    kill -s HUP $(cat $PIDF)
    ;;  
  *)    
        echo "Usage: $0 {start|stop|restart|reload}"
        exit 1  
esac            
exit 0
輸入:wq保存退出
[root@nginx nginx-1.12.2]# chmod +x /etc/init.d/nginx 
[root@nginx nginx-1.12.2]# chkconfig --add nginx
[root@nginx nginx-1.12.2]# yum install elinks -y
[root@nginx nginx-1.12.2]# service nginx start
[root@nginx nginx-1.12.2]# netstat -ntap | grep 80
tcp        0      0 0.0.0.0:80        0.0.0.0:*          LISTEN      42028/nginx: master 
[root@nginx nginx-1.12.2]# systemctl stop firewalld.service 
[root@nginx nginx-1.12.2]# setenforce 0
root@nginx nginx-1.12.2]# elinks http://192.168.18.136/
此時得到如下界面,可按q,選擇yes,回車退出

部署Nginx+Apache動靜分離(實戰!可跟做!)

此時在宿主機輸入:http://192.168.18.136/index.html 這個網址,會得到以下界面

部署Nginx+Apache動靜分離(實戰!可跟做!)

此時如果輸入:http://192.168.18.136/index.php 則無法處理,得到如下界面:

部署Nginx+Apache動靜分離(實戰!可跟做!)

第四步:做轉發處理:
[root@nginx nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
            proxy_pass   http://192.168.18.128;
        }
#以上內容意思為:動態請求轉交給誰去處理
#我們找到以上內容將前面的注釋去掉,并將其中的IP地址改為另外一臺7-3的地址
輸入:wq保存退出
[root@nginx nginx-1.12.2]# service nginx stop
[root@nginx nginx-1.12.2]# service nginx start
此時輸入:http://192.168.18.136/index.php 這個網址可以得到如下界面:
因為此處交給Apache去處理php的請求

部署Nginx+Apache動靜分離(實戰!可跟做!)

結論:后綴為html就是靜態元素,后綴為php就是動態元素,地址是不用改變的,因為我們在其中做了轉發處理!動靜分離實驗成功!

向AI問一下細節

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

AI

乐清市| 塔城市| 澄江县| 无锡市| 巨野县| 自贡市| 清流县| 娄烦县| 南溪县| 漳州市| 林周县| 哈尔滨市| 墨脱县| 七台河市| 兴宁市| 和田市| 宁安市| 湖南省| 九寨沟县| 兴化市| 长泰县| 莱州市| 延川县| 抚州市| 荆州市| 蚌埠市| 白城市| 雷州市| 朝阳市| 临泉县| 额尔古纳市| 时尚| 汕尾市| 磐石市| 连南| 云梦县| 陈巴尔虎旗| 美姑县| 新河县| 防城港市| 景东|