佛山宣傳片制作網(wǎng)站seo優(yōu)化方案策劃書
為了加快網(wǎng)站的解析速度,可以把動態(tài)頁面和靜態(tài)頁面由不同的服務(wù)器來解析,加快解析速度。降低原來單個(gè)服務(wù)器的壓力。 在動靜分離的tomcat的時(shí)候比較明顯,因?yàn)閠omcat解析靜態(tài)很慢,其實(shí)這些原理的話都很好理解,簡單來說,就是使用正則表達(dá)式匹配過濾,然后交個(gè)不同的服務(wù)器。
動靜分離
實(shí)質(zhì)?:使用正則表達(dá)式,匹配過濾,交給不同的服務(wù)器
優(yōu)點(diǎn)?:把動態(tài)頁面和靜態(tài)頁面分別由不同的服務(wù)器來解析,加快解析速度,降低單個(gè)服務(wù)器的壓力
環(huán)境準(zhǔn)備
靜態(tài)資源配置(10.36.192.169)
yum安裝nginx
訪問nginx的網(wǎng)站,nginx.org 進(jìn)去找到nginx的yum源
在命令行輸入echo '
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true ' > /etc/yum.repos.d/nginx.repo
清理緩存,生成自己緩存,列出yum倉庫
yum clean all
yum makecache
yum repolist
yum install yum-utils
yum -y install nginx
修改配置文件
vim /etc/nginx/conf.d/default.conf
server {listen 80;server_name localhost;location ~ \.(html|jpg|png|js|css|gif|bmp|jpeg) {root /usr/share/nginx/html;}
}
重啟nginx
nginx -t #檢查配置的語法有無問題
nginx -s reload #重載配置
動態(tài)資源配置(192.168.20.135)
yum安裝php
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php71w-xsl php71w php71w-ldap php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath php71w-mcrypt -y
yum install -y php71w-fpm
systemctl start php-fpm
systemctl enable php-fpm
yum 安裝nginx方法如上
修改nginx配置文件
vim /etc/nginx/conf.d/default.conf
server {listen 80;server_name localhost;location ~ \.php$ {root /usr/local/nginx/html; #指定網(wǎng)站目錄fastcgi_pass 127.0.0.1:9000; #指定訪問地址fastcgi_index index.php; #指定默認(rèn)文件fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #站點(diǎn)根目錄,取決于root配置項(xiàng)include fastcgi_params; #包含nginx常量定義}}
重啟nginx
nginx -t
nginx -s reload
nginx代理機(jī)配置(192.168.20.134)
修改nginx子自配置文件
vim /etc/nginx/conf.d/default.conf
upstream static {server 10.36.192.169 weight=1 max_fails=2 fail_timeout=2s;
}
upstream php {server 192.168.20.135 weight=2 max_fails=2 fail_timeout=2s;
}server {listen 80;server_name localhost;location ~ \.php$ {proxy_pass http://php;proxy_set_header Host $host:$server_port;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}
location ~ .*\.(html|gif|jpg|png|bmp|swf|css|js)$ {proxy_pass http://static;proxy_set_header Host $host:$server_port;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}
}
重啟nginx
nginx -t
nginx -s reload
客戶端訪問
? ?當(dāng)訪問靜態(tài)頁面的時(shí)候location 匹配到 (html|jpg|png|js|css|gif|bmp|jpeg) 通過轉(zhuǎn)發(fā)到靜態(tài)服務(wù)器,靜態(tài)服務(wù)通過location的正則匹配來處理請求。
? ?當(dāng)訪問動態(tài)頁面時(shí)location匹配到 .php 結(jié)尾的文件轉(zhuǎn)發(fā)到后端php服務(wù)處理請求。