• location练习!(重点)


    写location最重要的就是hosts文件,添加一次域名跳转就得添加一条hosts文件

    hosts文件:

    192.168.200.120   www.a.com
    
    192.168.200.119   www.b.com
    192.168.200.119   www.gx.com
    192.168.200.119   www.liuxiang.com
    192.168.200.119   www.img.com

    例题:

    第一题:输入www.b.com时网页跳转到www.jd.com

    第二题:输入www.gx.xom时网页跳转到www.taobao.com

    第三题:输入www.liuxiang.com/cai.com时网页跳转到自定义的cao.html

    第四题:输入www.img.com/images/时网页跳转到自定义的img.html下

    [root@localhost html]# vim cao.html                                   //自定义的页面

    <h1>caomengxia</h1>

    [root@localhost html]# ls
    50x.html    cao.html   error.jpg   img.html  index.html

    [root@localhost html]# vim ../conf/nginx.conf                             //不需再添加一个server直接写if或者location即可

    server {
             listen 80;
            server_name locahost;
            charset uft-8;
     access_log logs/host.access.log main;

    location / {
           root html;
          index index.html index.htm;
    }
    if ($host = "www.b.com") {                           //第一题
          rewrite (.*) http://www.jd.com;
    }
    if ($host = "www.gx.com") {                           //第二题
          rewrite (.*) http://www.taobao.com;
    }
    location ~ cai.html {                                    //第三题
        autoindex on;
        rewrite (.*) http://www.liuxiang.com/cao.html;
    }

    location ^~ /images/ {                               //第四题
         rewrite (.*) http://www.img.com/img.html;
    }

  • 相关阅读:
    [转载]网站运营粮草要先行
    微信公众平台开发(一) 配置接口
    UI框架说明
    布局
    DataGrid表格控件
    Dialog控件
    mysql出现 too many connections
    JVM调优案例
    ArrayBlockingQueue源码阅读
    jdk命令行工具
  • 原文地址:https://www.cnblogs.com/CMX_Shmily/p/11557455.html
Copyright © 2020-2023  润新知