zoukankan      html  css  js  c++  java
  • 马哥博客作业第十九周

    1、实现永久重定向,当用户访问 www.magedu.org 这个域名时我想让他跳转到
    www.magedu.com 的主页面,请写出配置过程
    定义子配置文件路径:

    [root@localhost ~]# vim /apps/nginx/conf/nginx.conf

    http{

        ......

        include /apps/nginx/conf/conf.d/*.conf

    }

    修改nginx配置文件,内容如下:

    [root@localhost ~]# vim /apps/nginx/conf/conf.d/pa.conf

    server {

        listen 80;

        server_name www.magedu.org;

        charset utf-8;

         location / {

            root /data/www;

            index index.html index.htm;

            rewrite ^(.*)$ http://www.magedu.com permanent;

         }

    }

    [root@localhost ~]# nginx -t

    [root@localhost ~]# nginx -s reload

    2、rewrite案例-判断文件是否存在,要求:当用户访问到公司网站的时输入了一个错误的 URL ,可以将用户重定向至 www.magedu.com 官网首页。请写出配置过程

    [root@localhost ~]# vim /apps/nginx/conf/conf.d/pb.conf

    server {

        listen 80;

        server_name www.magedu.org;

        charset utf-8;

        location / {

            root /data/www;

            index index.html index.htm;

            if (!-e $request_filename) {

            rewrite ^(.*)$ http://www.magedu.com;

            }

        }

    }

    [root@localhost ~]# nginx -t

    [root@localhost ~]# nginx -s reload

    3、用 nginx 做一个代理服务器,server_name 为 www.magedu.org,代理后端两台 apache 服务器。并且要求使用最少连接调度算法实现,这样才能做到后端 apache 服务器的压力大到均衡
    修改nginx主配置文件,内容如下:

    [root@localhost ~]# vim /apps/nginx/conf/nginx.conf

    upstream webserver {

        least_conn;

        server 10.0.0.11;

        server 10.0.0.12;

        }

    server {

        listen 80;

        server_name www.magedu.org;

        charset utf-8;

        location / {

            proxy_pass http://webserver;

            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }

    }

    检查Nginx语法

    [root@localhost ~]# nginx -t

    [root@localhost ~]# nginx -s reload

  • 相关阅读:
    Module:template
    Grunt:GruntFile.js
    Grunt:常见错误
    架构:架构-1
    架构:目录
    DS:template
    Jasper:用户指南 / 设备 / 生命周期管理 / SIM 卡状态
    Jasper-Api:接口测试
    linux服务之git
    Java实现 洛谷 P1487 陶陶摘苹果(升级版)
  • 原文地址:https://www.cnblogs.com/xuanlv-0413/p/13842793.html
Copyright © 2011-2022 走看看