這篇文章給大家分享的是Nginx實(shí)現(xiàn)動(dòng)靜分離處理的方法,相信大部分人都還沒學(xué)會(huì)這個(gè)技能,為了讓大家學(xué)會(huì),給大家總結(jié)了以下內(nèi)容,話不多說,一起往下看吧。
成都創(chuàng)新互聯(lián)不只是一家網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司;我們對(duì)營(yíng)銷、技術(shù)、服務(wù)都有自己獨(dú)特見解,公司采取“創(chuàng)意+綜合+營(yíng)銷”一體化的方式為您提供更專業(yè)的服務(wù)!我們經(jīng)歷的每一步也許不一定是最完美的,但每一步都有值得深思的意義。我們珍視每一份信任,關(guān)注我們的成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作質(zhì)量和服務(wù)品質(zhì),在得到用戶滿意的同時(shí),也能得到同行業(yè)的專業(yè)認(rèn)可,能夠?yàn)樾袠I(yè)創(chuàng)新發(fā)展助力。未來將繼續(xù)專注于技術(shù)創(chuàng)新,服務(wù)升級(jí),滿足企業(yè)一站式營(yíng)銷型網(wǎng)站需求,讓再小的品牌網(wǎng)站建設(shè)也能產(chǎn)生價(jià)值!
- Nginx的靜態(tài)處理能力很強(qiáng),但是動(dòng)態(tài)處理能力不足,因此,在企業(yè)中常用動(dòng)靜分離技術(shù)
- 針對(duì)PHP的動(dòng)靜分離
靜態(tài)頁面交給Nginx處理
動(dòng)態(tài)頁面交給PHP-FPM模塊或Apache處理- 在Nginx的配置中,是通過location配置段配個(gè)正則匹配實(shí)現(xiàn)靜態(tài)與動(dòng)態(tài)頁面的不同處理方式
LAMP服務(wù)器(192.168.13.139)
Nginx服務(wù)器(192.168.13.140)
[root@lamp ~]# yum install httpd httpd-devel -y ##安裝http服務(wù)及開發(fā)包
[root@lamp ~]# systemctl start httpd.service ##開啟服務(wù)
[root@lamp ~]# firewall-cmd --permanent --zone=public --add-service=http ##防火墻允許http
success
[root@lamp ~]# firewall-cmd --permanent --zone=public --add-service=https
success
[root@lamp ~]# firewall-cmd --reload ##重啟防火墻
success
[root@lamp ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel -y
##安裝數(shù)據(jù)庫(kù)
[root@lamp ~]# systemctl start mariadb ##開啟數(shù)據(jù)庫(kù)
[root@lamp ~]# netstat -ntap | grep 3306 ##查看端口號(hào)3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2200/MySQLd
[root@lamp ~]# mysql_secure_installation ##設(shè)置數(shù)據(jù)庫(kù)
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è)置root密碼
New password: ##輸入密碼
Re-enter new password: ##確認(rèn)密碼
Remove anonymous users? [Y/n] n ##允許匿名訪問
... skipping.
Disallow root login remotely? [Y/n] n ##允許遠(yuǎn)程登錄
... skipping.
Remove test database and access to it? [Y/n] n ##保留測(cè)試數(shù)據(jù)庫(kù)
... skipping.
Reload privilege tables now? [Y/n] y ##重啟數(shù)據(jù)庫(kù)
... 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@lamp ~]# yum install php -y ##安裝PHP
[root@lamp ~]# yum install php-mysql -y ##建立php和mysql關(guān)聯(lián)
[root@lamp ~]# yum install -y \
> php-gd ##GD庫(kù)是php處理圖形的擴(kuò)展庫(kù)
> php-ldap ##輕量級(jí)目錄訪問協(xié)議
> php-odbc ##應(yīng)用程序編程接口
> php-pear ##擴(kuò)展應(yīng)用代碼庫(kù)
> php-xml php-xmlrpc ##xml文件
> php-mbstring ##多字節(jié)字符串
> php-snmp ##管理端開發(fā)
> php-soap ##SOAP 擴(kuò)展可以用來提供和使用 Web Services
> curl curl-devel ##支持?jǐn)?shù)據(jù)文件下載工具
> php-bcmath ##BCMath庫(kù)來支持更加精確的計(jì)算
[root@lamp ~]# cd /var/www/html/ ##切換到站點(diǎn)
[root@lamp html]# vim index.php ##編輯php網(wǎng)頁內(nèi)容
<?php
phpinfo();
?>
[root@lamp html]# vim index.php ##編輯php網(wǎng)頁內(nèi)容
<?php
echo "apache web !"
?>
[root@localhost ~]# smbclient -L //192.168.100.3/ ##遠(yuǎn)程共享訪問
Enter SAMBA\root's password:
Sharename Type Comment
--------- ---- -------
LNMP-C7 Disk
[root@localhost ~]# mount.cifs //192.168.100.3/LNMP-C7 /mnt ##掛載到/mnt目錄下
[root@localhost ~]# cd /mnt ##切換到掛載點(diǎn)目錄
[root@localhost mnt]# ls
Discuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gz
mysql-boost-5.7.20.tar.gz php-7.1.20.tar.gz
[root@localhost mnt]# tar zxvf nginx-1.12.2.tar.gz -C /opt ##解壓Nginx源碼包到/opt下
[root@localhost mnt]# cd /opt/ ##切換到解壓的目錄下
[root@localhost opt]# ls
nginx-1.12.2 rh
[root@localhost opt]# yum -y install \
gcc \ //c語言
gcc-c++ \ //c++語言
pcre-devel \ //pcre語言工具
zlib-devel //數(shù)據(jù)壓縮用的函式庫(kù)
[root@localhost opt]# useradd -M -s /sbin/nologin nginx ##創(chuàng)建程序用戶,安全不可登陸狀態(tài)
[root@localhost opt]# id nginx
uid=1001(nginx) gid=1001(nginx) 組=1001(nginx)
[root@localhost opt]# cd nginx-1.12.0/ ##切換到nginx目錄下
[root@localhost nginx-1.12.0]# ./configure \ ##配置nginx
> --prefix=/usr/local/nginx \ ##安裝路徑
> --user=nginx \ ##用戶名
> --group=nginx \ ##用戶組
> --with-http_stub_status_module ##狀態(tài)統(tǒng)計(jì)模塊
[root@localhost nginx-1.12.0]# make ##編譯
...
[root@localhost nginx-1.12.0]# make install ##安裝
...
[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
##創(chuàng)建軟連接讓系統(tǒng)識(shí)別nginx啟動(dòng)腳本
[root@localhost nginx]# cd /etc/init.d/ ##切換到啟動(dòng)配置文件目錄
[root@localhost init.d]# ls
functions netconsole network README
[root@localhost init.d]# vim nginx ##編輯啟動(dòng)腳本文件
#!/bin/bash
# chkconfig: - 99 20 ##注釋信息
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx" ##設(shè)置變量為nginx命令文件
PIDF="/usr/local/nginx/logs/nginx.pid" ##設(shè)置變量PID文件 進(jìn)程號(hào)為5346
case "$1" in
start)
$PROG ##開啟服務(wù)
;;
stop)
kill -s QUIT $(cat $PIDF) ##關(guān)閉服務(wù)
;;
restart) ##重啟服務(wù)
$0 stop
$0 start
;;
reload) ##重載服務(wù)
kill -s HUP $(cat $PIDF)
;;
*) ##錯(cuò)誤輸入提示
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
[root@localhost init.d]# chmod +x /etc/init.d/nginx ##給啟動(dòng)腳本執(zhí)行權(quán)限
[root@localhost init.d]# chkconfig --add nginx ##添加到service管理器中
[root@localhost init.d]# service nginx stop ##就可以使用service控制nginx
[root@localhost init.d]# service nginx start
[root@localhost init.d]# yum install elink -y ##安裝軟件
[root@localhost init.d]# netstat -ntap | grep 80 ##查看Nginx端口
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 44663/nginx: master
[root@localhost init.d]# systemctl stop firewalld.service ##關(guān)閉防火墻
[root@localhost init.d]# setenforce 0
[root@localhost init.d]# elinks http://192.168.13.140/ ##測(cè)試網(wǎng)頁
[root@localhost init.d]# vim /usr/local/nginx/conf/nginx.conf ##修改配置文件
location ~ \.php$ { ##找到此處將注釋去除,開啟動(dòng)靜分離
proxy_pass http://192.168.13.139; ##填寫動(dòng)態(tài)處理的Apache的服務(wù)器地址
}
[root@localhost init.d]# service nginx stop ##關(guān)閉
[root@localhost init.d]# service nginx start ##開啟
看完上述內(nèi)容,你們掌握Nginx實(shí)現(xiàn)動(dòng)靜分離處理的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
網(wǎng)站欄目:Nginx實(shí)現(xiàn)動(dòng)靜分離處理
分享路徑:http://chinadenli.net/article10/gespdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、云服務(wù)器、定制網(wǎng)站、建站公司、動(dòng)態(tài)網(wǎng)站、App開發(fā)
聲明:本網(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í)需注明來源: 創(chuàng)新互聯(lián)