zoukankan      html  css  js  c++  java
  • 十九.部署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测试:
     
    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 永久重定向
    **********************
  • 相关阅读:
    go 接收发送文件
    【0031】反转整数/判断回文
    【003】链表或字符串的【反转】【左旋转】
    【002】链表或字符串模拟加法/加一/乘法
    【01】数组中只出现一次的数字
    【面试题050】树中两个结点的最低公共祖先
    【面试题049】把字符串转换成整数
    【面试题048】不能继承的类
    【面试题047】不用加减乘除做加法
    【面试题046】求1+2+...+n
  • 原文地址:https://www.cnblogs.com/luwei0915/p/10483949.html
Copyright © 2011-2022 走看看