本文小編為大家詳細(xì)介紹“部署Nginx+Apache動(dòng)靜分離的方法”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“部署Nginx+Apache動(dòng)靜分離的方法”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來(lái)學(xué)習(xí)新知識(shí)吧。
目前成都創(chuàng)新互聯(lián)已為近千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)絡(luò)空間、網(wǎng)站托管、服務(wù)器租用、企業(yè)網(wǎng)站設(shè)計(jì)、五指山網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
nginx動(dòng)靜分離介紹
nginx的靜態(tài)處理能力很強(qiáng),但是動(dòng)態(tài)處理能力不足,因此,在企業(yè)中常用動(dòng)靜分離技術(shù)
針對(duì)php的動(dòng)靜分離
靜態(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è)面的不同處理方式
反向代理原理
nginx不僅能作為web服務(wù)器,還具有反向代理、負(fù)載均衡和緩存的功能
nginx通過(guò)proxy模塊實(shí)現(xiàn)將客戶端的請(qǐng)求代理至上游服務(wù)器,此時(shí)nginx與上游服務(wù)器的連接是通過(guò)http協(xié)議進(jìn)行的
nginx在實(shí)現(xiàn)反向代理功能時(shí)的最重要指令為proxy_ pass,它能夠并能夠根據(jù)uri、客戶端參數(shù)或其它的處理邏輯將用戶請(qǐng)求調(diào)度至上游服務(wù)器
配置nginx實(shí)現(xiàn)動(dòng)靜分離
本案例根據(jù)企業(yè)需要,將配置nginx實(shí)現(xiàn)動(dòng)靜分離,對(duì)php頁(yè)面的請(qǐng)求轉(zhuǎn)發(fā)給lamp處理,而靜態(tài)頁(yè)面交給nginx處理,以實(shí)現(xiàn)動(dòng)靜分離
架構(gòu)如圖所示
配置步驟
1、架設(shè)并調(diào)試后端lamp環(huán)境
①安裝apache服務(wù)
[root@localhost ~]# yum install httpd httpd-devel -y
②在防火墻設(shè)置http服務(wù)的權(quán)限
[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
③安裝mariadb
mariadb數(shù)據(jù)庫(kù)管理系統(tǒng)是MySQL的一個(gè)分支,主要由開源社區(qū)在維護(hù),采用gpl授權(quán)許可 mariadb的目的是完全兼容mysql,包括api和命令行,使之能輕松成為mysql的代替品
[root@localhost ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y [root@localhost ~]# systemctl start mariadb.service
④mysql安全配置向?qū)?/p>
[root@localhost ~]# mysql_secure_installation
⑤安裝php及支持的軟件
[root@localhost ~]# yum install php -y [root@localhost ~]# yum install php-mysql -y [root@localhost ~]# yum install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath -y
⑥更改網(wǎng)頁(yè)主頁(yè)面
[root@localhost ~]# cd /var/www/html [root@localhost html]# vim index.php <?php echo "this is apache test web"; ?> [root@localhost html]# systemctl restart httpd
⑦訪問(wèn)測(cè)試,輸入網(wǎng)址
2、編譯安裝nginx
①安裝支持軟件
[root@localhost ~]# yum install gcc gcc-c++ pcre-devel zlib-devel -y
②創(chuàng)建運(yùn)行用戶和組
[root@localhost ~]# useradd -m -s /sbin/nologin nginx
③編譯安裝
[root@localhost lnmp-c7]# tar zxvf nginx-1.12.2.tar.gz -c /opt [root@localhost lnmp-c7]# cd /opt/nginx-1.12.2/ [root@localhost nginx-1.12.2]# ./configure \ > --prefix=/usr/local/nginx \ > --user=nginx \ > --group=nginx \ > --with-http_stub_status_module [root@localhost nginx-1.12.2]# make && make install [root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
④服務(wù)管理控制
[root@localhost ~]# vim /etc/init.d/nginx #!/bin/bash # chkconfig: - 99 20 # description: ngins 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 [root@localhost ~]# chmod +x /etc/init.d/nginx [root@localhost ~]# chkconfig --add nginx [root@localhost ~]# service nginx start
⑤啟動(dòng)服務(wù)
[root@nginx ~]# systemctl stop firewalld.service [root@nginx ~]# setenforce 0 [root@nginx ~]# service nginx start
⑥配置nginx處理動(dòng)態(tài)頁(yè)面請(qǐng)求
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf location ~ \.php$ { proxy_pass http://192.168.150.214; } [root@nginx ~]# service nginx restart
⑦訪問(wèn)測(cè)試
讀到這里,這篇“部署Nginx+Apache動(dòng)靜分離的方法”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過(guò)才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
本文題目:部署Nginx+Apache動(dòng)靜分離的方法
文章位置:http://muchs.cn/article10/jpeddo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、標(biāo)簽優(yōu)化、品牌網(wǎng)站設(shè)計(jì)、外貿(mào)建站、網(wǎng)站維護(hù)、電子商務(wù)
聲明:本網(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)