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

  • 相关阅读:
    CF431E Chemistry Experiment
    BZOJ 4173: 数学
    BZOJ 2426: [HAOI2010]工厂选址
    BZOJ 2580: [Usaco2012 Jan]Video Game
    BZOJ 4237: 稻草人
    BZOJ 2434: [Noi2011]阿狸的打字机
    BZOJ 3881: [Coci2015]Divljak
    BZOJ 2754: [SCOI2012]喵星球上的点名
    BZOJ 1009: [HNOI2008]GT考试
    BZOJ 3731: Gty的超级妹子树
  • 原文地址:https://www.cnblogs.com/xuanlv-0413/p/13842793.html
Copyright © 2011-2022 走看看