Rewrite 需求作业

背景:现在我有一个网站,www.linux.com

www.linux.com访问主页面

friend.linux.com访问交友页面

blog.linux.com访问博客页面

download.linux.com访问博客页面

在nginx上部署三套代码

使用rewrite和return两种方式完成以下需求

1、通过www.linux.com/download访问到下载页面

2、通过www.linux.com/friends访问到交友页面

3、通过www.linux.com/blog访问到博客页面


部署网站

[root@web03 ~]# vim /etc/nginx/conf.d/ln.conf
server {
listen 80;
server_name www.linux.com; location / {
root /code/dist;
index index.html;
}
} server {
listen 80;
server_name friend.linux.com; location / {
root /code/friend;
index friend.html;
}
} server {
listen 80;
server_name blog.linux.com; location / {
root /code/blog;
index blog.html;
}
} server {
listen 80;
server_name download.linux.com; location / {
root /code/download;
index down.html;
}
} [root@web01 conf.d]# mkdir /code -p && cd /code
#上传前端代码文件rz
[root@web01 code]# unzip 下载页面.zip
[root@web01 code]# unzip 主页面.zip
[root@web01 code]# unzip 交友页面.zip
[root@web01 code]# unzip 博客页面.zip [root@web01 code]# nginx -sreload
[root@web01 code]# nginx

rewrite重定向

[root@web03 code]# vim /etc/nginx/conf.d/ln.conf
server {
listen 80;
server_name www.linux.com; location / {
root /code/dist;
index index.html;
} location ~* ^/(download|friend|blog) {
rewrite ^/(.*)$ http://$1.linux.com redirect;
}
} server {
listen 80;
server_name friend.linux.com; location / {
root /code/friend;
index friend.html;
}
} server {
listen 80;
server_name blog.linux.com; location / {
root /code/blog;
index blog.html;
}
} server {
listen 80;
server_name download.linux.com; location / {
root /code/download;
index down.html;
}
}

return重定向

[root@web03 code]# vim /etc/nginx/conf.d/ln.conf

server {
listen 80;
server_name www.linux.com; location / {
root /code/dist;
index index.html;
} server_name www.linux.com; location / {
root /code/dist;
index index.html;
} location ~* ^/(download|friend|blog) {
return 302 http://$request_uri.linux.com;
}
} server {
listen 80;
server_name friend.linux.com; location / {
root /code/friend;
index friend.html;
}
} server {
listen 80;
server_name blog.linux.com; location / {
root /code/blog;
index blog.html;
}
} server {
listen 80;
server_name download.linux.com; location / {
root /code/download;
index down.html;
}
} [root@web03 code]# nginx -sreload

rewrite和return的简单需求的更多相关文章

  1. 【04】Nginx:rewrite / if / return / set 和变量

    写在前面的话 我们前面已经谈了编译安装,基本语法,日志处理,location 匹配,root / alias 的不同效果.这里我们主要谈谈 rewrite(重写)功能,顺便说说 nginx 中自带的变 ...

  2. 由一个简单需求到Linux环境下的syslog、unix domain socket

    本文记录了因为一个简单的日志需求,继而对linux环境下syslog.rsyslog.unix domain socket的学习.本文关注使用层面,并不涉及rsyslog的实现原理,感兴趣的读者可以参 ...

  3. 一个简单需求:HashMap实现相同key存入数据后不被覆盖

    做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! 看似是一个简单的问题,其实里面包含很多的东西! 需求: 实现一个在HashMap中存入(任意类型)相同的key值后,key ...

  4. 从简单需求到OLAP的RANK系列函数

    同事问了一个非常简单的问题,怎么取出每个partition里面另外一个列的最小值? create table t1 (int c1, int c2);   假如按照c2分区,0-10,10-20,20 ...

  5. JavaScript return 最简单解释

    一.return 返回值 1)函数名字 +括号 :fun() ==> retrun 后面的值 2)所以函数的模范返回值是为未定义 3)return; 后面的任何代码都不会执行了 二.arguem ...

  6. Nginx 配置 location 以及 return、rewrite 和 try_files 指令

    正则表达式 Nginx 内置的全局变量 location 前缀字符串及优先级 示例 location 匹配原则 if 和 break 指令 if break return.rewrite 和 try_ ...

  7. 04 . Nginx的Rewrite重写

    Rewrite简介 # Rewrite对应URL Rewrite,即URL重写,就是把传入web的请求重定向到其他URL的过程. # 当运维遇到要重写情况时,往往是要程序员把重写规则写好后,发给你,你 ...

  8. 可惜Java中没有yield return

    项目中一个消息推送需求,推送的用户数几百万,用户清单很简单就是一个txt文件,是由hadoop计算出来的.格式大概如下: uid caller 123456 12345678901 789101 12 ...

  9. ASP.NET WEBAPI 简单CURD综合测试(asp.net MVC,json.net,sql基础存储过程和视图,sqlhelper,json解析)

    草图   真正的后端是不管前端是什么平台,用什么语言的,JSON格式的数据应该可以应对.用ASP.NET WEBAPI尝试做一个后端,实现最基本的CURD,业务逻辑和数据库操作都放在后端,前端只需要正 ...

随机推荐

  1. P2762 太空飞行计划问题 网络流

    题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,Em},和进行这些实验需要使用的全部仪器的 ...

  2. Vue列表实现滚动到指定位置样式改变

    这个需求大概是这样子: 我做的一个聊天Demo,在搜索框搜索用户,可以滚动到指定的用户.然后成选中状态. 这是目前状态,我搜索 南宫仆射 ,想要下面的用户列表直接滚动到 南宫仆射 并改变CSS样式. ...

  3. Spring Cloud 学习 之 Spring Cloud Ribbon(基础知识铺垫)

    文章目录 1.负载均衡: 2.RestTemplate详解: xxxForEntity/xxxForObject:主要介绍get跟post exchange: execute源码分析: 1.负载均衡: ...

  4. Day_08【面向对象】扩展案例4_年龄为30岁的老王养了一只黑颜色的2岁的宠物……

    #分析以下需求,并用代码实现: 1.定义动物类 属性: 年龄,颜色 行为: eat(String something)方法(无具体行为,不同动物吃的方式和东西不一样,something表示吃的东西) ...

  5. c++(qt)程序员微信群

    关注微信公众号"程序员成长日志",回复关键字"c++"扫码进群 本群主要为大家解决工作中遇到的问题遇到的问题发到群里大家集思广益平时可以瞎扯不定期红包

  6. JDBC14 ORM03 JavaBean封装

    Javabean对象封装一条信息(推荐) 让JavaBean的属性名和类型尽量和数据库保持一致 一条记录对应一个对象,将这些查询到的对象放到容器中(List) 表信息如下 List封装多条信息 Con ...

  7. Python Web自动化测试入门与实战,从入门到入行

    Python Web自动化测试入门与实战 购买地址 · 京东:https://item.jd.com/69239480564.html   天猫:https://detail.tmall.com/it ...

  8. SpringBoot基础实战系列(二)springboot解析json与HttpMessageConverter

    SpringBoot解析Json格式数据 @ResponseBody 注:该注解表示前端请求后端controller,后端响应请求返回 json 格式数据前端,实质就是将java对象序列化 1.创建C ...

  9. Nginx|构建简单的文件服务器(mac) 续-FastDFS安装(mac)|文件存储方案

    目录 Nginx|构建简单的文件服务器(mac) 1 所需安装包 2 安装fastdfs-nginx-module-master 3 安装Nginx Nginx|构建简单的文件服务器(mac) 续上文 ...

  10. js对页面中的内容进行拼音搜索,只对后台已经传过来的页面数据进行索引

    实现输入拼音(可以使用拼音首字母来查),来查询出已经存在于页面的数据 注意:这种写法只能适用于页面中已经存在的数据进行检索,大体意思是将本页内的数据拼接成一个字符串,然后通过该字符串去检索匹配的字符串 ...