proxy client web1 web2
 
1.部署LNMP环境
1.1 部署nginx(前面已部署过)
1.2 部署mariadb
]# yum -y install mariadb mariadb-server mariadb-devel
]# systemctl start mariadb
]# systemctl enable mariadb 
]# mysql
1.3 部署php
]# yum -y install php php-mysql php-fpm
]# yum -y install php-fpm-5.4.16-42.el7.x86_64.rpm(自备)
]# systemctl start php-fpm
]# systemctl status php-fpm
]# systemctl enable php-fpm 
 
2.构建LNMP平台
2.1 查看php-fpm配置文件(实验中不需要修改该文件)
[root@proxy etc]# vim /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000    //PHP端口号
pm.max_children = 32       //最大进程数量
pm.start_servers = 15      //最小进程数量
pm.min_spare_servers = 5   //最少需要几个空闲着的进程
pm.max_spare_servers = 32  //最多允许几个进程处于空闲状态
2.2 修改Nginx配置文件支持php页面,并启动服务
]# vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
   root           html;
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index  index.php;
 # fastcgi_param  SCRIPT_FILENAME /scripts$fastcgi_script_name;
   include        fastcgi.conf;
   }
 
]# nginx -s reload
2.3 创建PHP测试页面,连接并查询MariaDB数据库
~]# vim /usr/local/nginx/html/test.php
<?php
$mysqli = new mysqli('localhost','root','123qqq...A','mysql');
if (mysqli_connect_error()){
    die('Unable to connect!'). mysqli_connect_error();
}
$sql = "select * from user";
$result = $mysqli->query($sql);
while($row = $result->fetch_array()){
    printf("Host:%s",$row[0]);
    printf("</br>");
    printf("Name:%s",$row[1]);
    printf("</br>");
}
?>
client测试:
 
3.地址重写
3.1 修改配置文件(访问a.html重定向到b.html)
]# vim /usr/local/nginx/conf/nginx.conf
... 
server_name  www.a.com;
  rewrite /a.html /b.html;
...
]# nginx -s reload
]# echo "aaa" > /usr/local/nginx/html/a.html
]# echo "bbb" > /usr/local/nginx/html/b.html
client测试:
]# firefox 192.168.4.5/a.html
]# firefox 192.168.4.5/b.html
3.2 访问a.html重定向到b.html(跳转地址栏)
]# vim /usr/local/nginx/conf/nginx.conf
...
server_name  www.a.com;
   rewrite /a.html /b.html redirect;
...
]# nginx -s reload
client测试:
]# firefox 192.168.4.5/a.html
3.3 修改配置文件(访问192.168.4.5的请求重定向至www.baidu.com)
]# vim /usr/local/nginx/conf/nginx.conf
...
server_name  www.a.com;
  rewrite ^/ http://www.baidu.com/;
...
]# nginx -s reload
]# firefox 192.168.4.5
3.4 修改配置文件(访问192.168.4.5/下面子页面,重定向至www.baidu.com/下相同的页面)
]# vim /usr/local/nginx/conf/nginx.conf
...
server_name  www.a.com;
  rewrite ^/(.*)$ http://www.baidu.com/$1;
...
]# nginx -s reload
lient测试:
]# firefox 192.168.4.5/a.html
3.5 修改配置文件(实现curl和火狐访问相同链接返回的页面不同)
]# echo "I am Normal page" > /usr/local/nginx/html/test.html
]# mkdir -p /usr/local/nginx/html/firefox/
]# echo "firefox page" > /usr/local/nginx/html/firefox/test.html
]# vim /usr/local/nginx/conf/nginx.conf
...
location / {
   root   html;
   index index.php index.html index.htm;
    }
 
if ($http_user_agent ~* firefox) {
             
    rewrite ^(.*)$ /firefox/$1;
    }
...
]# nginx -s reload
client 测试:
**********************
地址重写格式【总结】
rewrite 旧地址 新地址 [选项];
last 不再读其他rewrite
break 不再读其他语句,结束请求
redirect 临时重定向
permament 永久重定向
**********************

最新文章

  1. AspNetPager分页控件样式的使用
  2. SmallPtAMP: C++ AMP implementation of SmallPt / SmallPtGPU
  3. 万恶的jar包冲突
  4. Jquery 随便写些知识点
  5. linux 安装vbox增强工具
  6. C语言处理xml文件的库
  7. 【JavaScript】JQuery中$.fn、$.extend、$.fn.extend
  8. 简单修改hosts文件加快打开网页速度
  9. 在JSP中使用jQuery的冲突解决(收集整理)
  10. elasticsearch nested查询
  11. 12-27 UITableView常用属性及方法
  12. win7x64安装wince6
  13. Json.Net学习.集合序列化.
  14. mysql违背了唯一约束
  15. DTcms手机版使用余额支付 提示信息跳转到PC版的错误。以及提交订单不打开新页面
  16. I2C总线协议的总结介绍
  17. laravel 心得
  18. concurrent实用类
  19. HDU 5569 matrix
  20. docker 部署 java 项目

热门文章

  1. 使用keepalived实现kubenetes apiserver高可用
  2. PAT(B) 1062 最简分数(Java)
  3. 全面优化MySQL
  4. python检测挖矿特征的几种方式
  5. Spring AOP日志实现(一)
  6. 海思SDK 与各芯片对照
  7. hdu 6661 Acesrc and String Theory (后缀数组)
  8. ELK搜索条件
  9. Flask无法访问(127.0.0.1:5000)的问题解决方法
  10. vue+iview 通过a标签实现文件下载