为了加快网站的解析速度,可以把动态页面和静态页面由不同的服务器来解析,加快解析速度。降低原 来单个服务器的压力。 简单来说,就是使用正则表达式匹配过滤,然后交个不同的服务器。
1、准备环境
准备一个nginx代理 两个http 分别处理动态和静态。
1.配置编译安装的nginx为反向代理upstream;
upstream static { server 10.0.105.196:80 weight=1 max_fails=1 fail_timeout=60s; } upstream php { server 10.0.105.200:80 weight=1 max_fails=1 fail_timeout=60s; } server { listen server_name #动态资源加载 80; localhost location ~ \.(php|jsp)$ { proxy_pass http://phpserver; 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|jpg|png|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; } }
静态资源配置---10.0.105.196
server { listen 80; server_name localhost; location ~ \.(html|jpg|png|js|css)$ { root /var/www/nginx; } }
上传图片
动态资源配置: 10.0.105.200
yum 安装php7.1
[root@nginx-server ~]#rpm -Uvh https://mirror.webtatic.com/yum/el7/epel- release.rpm
[root@nginx-server ~]#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic- release.rpm
[root@nginx-server ~]#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
[root@nginx-server ~]#yum install -y php71w-fpm [root@nginx-server ~]#systemctl start php-fpm [root@nginx-server ~]#systemctl enable php-fpm
编辑nginx的配置文件:
[root@nginx-server ~]# cd /etc/nginx/conf.d/ [root@nginx-server conf.d]# vim phpserver.conf server {
listen 80;
server_name localhost; location ~ \.php$ {
root /home/nginx/html; #指定网站目录
fastcgi_pass fastcgi_index fastcgi_param
#站点根目录,取决于root配置项
include
}
}
127.0.0.1:9000; #指定访问地址
index.php;
#指定默认文件
SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_params; #包含nginx常量定义
当访问静态页面的时候location 匹配到 (html|jpg|png|js|css) 通过转发到静态服务器,静态服务通过
location的正则匹配来处理请求。
当访问动态页面时location匹配到 .\php 结尾的文件转发到后端php服务处理请求。
知识点扩展:
通过请求分离
[root@lb01 conf]# vim nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream stack_pools { server 172.25.254.134:80 weight=5; } upstream dynamic_pools { server 172.25.254.135:80 weight=5; } server { listen 80; server_name www.lbtest.com; location / { root html; index index.html index.htm; proxy_set_header Host $host; proxy_pass http://dynamic_pools; } location /image/ { proxy_set_header Host $host; proxy_pass http://stack_pools; } location /dynamic/ { proxy_set_header Host $host; proxy_pass http://dynamic_pools; } } } [root@lb01 conf]# nginx -s reload
根据扩展名分离
[root@lb01 conf]# vim nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream stack_pools { server 172.25.254.134:80 weight=5; } upstream dynamic_pools { server 172.25.254.135:80 weight=5; } server { listen 80; server_name www.lbtest.com; location / { root html; index index.html index.htm; proxy_set_header Host $host; proxy_pass http://dynamic_pools; } location ~ .*.(jpg|png|gif|css|js|swf|bmp|jsp|php|asp)$ { proxy_set_header Host $host; proxy_pass http://stack_pools; } } } [root@lb01 conf]# nginx -s reload
nginx,动静分离
更新日志
- 黄乙玲1988-无稳定的爱心肝乱糟糟[日本东芝1M版][WAV+CUE]
- 群星《我们的歌第六季 第3期》[320K/MP3][70.68MB]
- 群星《我们的歌第六季 第3期》[FLAC/分轨][369.48MB]
- 群星《燃!沙排少女 影视原声带》[320K/MP3][175.61MB]
- 乱斗海盗瞎6胜卡组推荐一览 深暗领域乱斗海盗瞎卡组分享
- 炉石传说乱斗6胜卡组分享一览 深暗领域乱斗6胜卡组代码推荐
- 炉石传说乱斗本周卡组合集 乱斗模式卡组最新推荐
- 佟妍.2015-七窍玲珑心【万马旦】【WAV+CUE】
- 叶振棠陈晓慧.1986-龙的心·俘虏你(2006复黑限量版)【永恒】【WAV+CUE】
- 陈慧琳.1998-爱我不爱(国)【福茂】【WAV+CUE】
- 咪咕快游豪礼放送,百元京东卡、海量欢乐豆就在咪咕咪粉节!
- 双11百吋大屏焕新“热”,海信AI画质电视成最大赢家
- 海信电视E8N Ultra:真正的百吋,不止是大!
- 曾庆瑜1990-曾庆瑜历年精选[派森][WAV+CUE]
- 叶玉卿1999-深情之选[飞图][WAV+CUE]