青春纸盒子

文: 芦苇

你喜欢我笑的样子

我靠上了落寞的窗子

晚风吹起了我的袖子

明月沾湿了你的眸子


转身,你走出了两个人的圈子

树影婆娑,整座院子


挽起袖子

回头,把揽你忧伤一地的影子

装进,青春,这纸盒子


更多代码请关注我的微信小程序: "ecoder"

luwei0915

导航

十九.部署LNMP环境、构建LNMP平台、地址重写

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测试:
]# firefox http://192.168.4.5/test.php
 
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 测试:
]# firefox http://192.168.4.5/test.html
]# curl http://192.168.4.5/test.html
**********************
地址重写格式【总结】
rewrite 旧地址 新地址 [选项];
last 不再读其他rewrite
break 不再读其他语句,结束请求
redirect 临时重定向
permament 永久重定向
**********************

posted on 2019-03-06 16:14  芦苇の  阅读(164)  评论(0编辑  收藏  举报