|
构建Apache+Nginx动静分离
实验目的:html静态页面由nginx处理,php动态页面交给apache处理
目录
第一部分 准备工作
第二部分 配置apache+nginx动静分离
第三部分 测试验证
第一部分 环境准备
一:服务器两台:Linux系统—CentOS 7.4
IP地址:192.168.80.10(搭建LAMP)
192.168.80.40(搭建LNMP)
http://i2.51cto.com/images/blog/201804/09/e5ec407ed579abcda447d5b41ad308d6.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
客户端一台:以WIN7为例,用来测试验证,与服务器同一网段
IP地址:192.168.80.2
二:将防火墙与selinux关闭
http://i2.51cto.com/images/blog/201804/09/b9600ac7c7f8364882ebadd80485ddda.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
注意:LAMP的搭建参考http://blog.51cto.com/12227558/2074113
LNMP的搭建参考http://blog.51cto.com/12227558/2084690
第二部分 配置Apache+Nginx动静分离
第一步:Apache服务器配置
[iyunv@localhost ~]# cd /usr/local/httpd/htdocs/
[iyunv@localhost htdocs]# vi index.php //配置动态页面
http://i2.51cto.com/images/blog/201804/09/7f67f34e1bedd888fac251d70cb8d5b1.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
保存退出
[iyunv@localhost htdocs]# service httpd restart //重启http服务
第二步:nginx服务器配置
[iyunv@localhost ~]# vi /usr/local/nginx/conf/nginx.conf //编辑主配置文件
- 如果nginx服务配置了fpm模块(支持处理php网页),先做以下操作
将以下内容注释掉(关闭该模块使它不支持处理动态页面的能力):
http://i2.51cto.com/images/blog/201804/09/f06ca2a7e4742047eaed92a24b6c63ac.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk= - 将动态页面指定给apache
修改以下内容:
http://i2.51cto.com/images/blog/201804/09/c33c23220679ff4aa80b029d3c38494e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk= - 静态页面指定本地处理
添加以下内容:
http://i2.51cto.com/images/blog/201804/09/41f4b0df7e85643e2d8a2dfc81792cbc.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
(注意,最后一行是数字“1”d,代表有效期一天)
保存退出
[iyunv@localhost ~]# nginx –t //检查语法错误
http://i2.51cto.com/images/blog/201804/09/b3094fa2b0aef4d8fe02fcdb73d6ecf1.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk= - [iyunv@localhost ~]# systemctl restart nginx //重启nginx服务
http://i2.51cto.com/images/blog/201804/09/8d1384a8c8c7719870bee2df258cc27e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
第三部分 验证测试
//用Wireshark抓包测试,验证http数据包走向
- 访问静态页面:192.168.80.40/index.html
http://i2.51cto.com/images/blog/201804/09/2a1e6b5aeb72667506de9b9544b25042.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
http://i2.51cto.com/images/blog/201804/09/b5a1dae92d0b85a5a9f6ef239f600138.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
(1)客户端向nginx请求
(2)Nginx直接回复客户端 - 访问动态页面:192.168.80.40/index.php
http://i2.51cto.com/images/blog/201804/09/eb4f14115fe1e198f092aae62f347f36.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
http://i2.51cto.com/images/blog/201804/09/7950c492185c4a0ba94ee8ab994d2a69.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=
(1)客户端向nginx服务器请求
(2)nginx服务器向apache服务器请求
(3)apache回复nginx的请求
(4)nginx回复客户端的请求
|
|
|