4.2.2 实例操作:基于客户端 IP 访问跳转
(1)修改配置文件

文章插图

文章插图
(2)检查配置文件并重启服务

文章插图
(3)创建跳转后的网页目录和内容

文章插图
(4)浏览器访问测试
本机访问:

文章插图
其它主机访问:
现在域名IP地址做映射:

文章插图
然后再访问:

文章插图
4.3基于旧域名跳转到新域名后面加目录4.3.1基于旧域名跳转到新域名后面加目录的操作步骤
现在访问的是 http://bbs.fzr.com/test,现在需要将这个域名下面的访问都跳转到http://www.fzr.com/bbs/test
vim /usr/local/nginx/conf/nginx.confserver { listen 80; server_name bbs.fzr.com; #域名修改 charset utf-8; access_log /var/log/nginx/bbs.fzr.com-access.log; #添加 location /test { rewrite (.+) http://www.fzr.com/bbs$1 permanent; #这里的$1为位置变量 , 代表/test } location / { root html; index index.html index.htm; }}mkdir -p /usr/local/nginx/html/bbs/postecho "this is web" >> /usr/local/nginx/html/bbs/post/1.htmlecho "192.168.10.10 bbs.fzr.com www.fzr.com" >> /etc/hostssystemctl restart nginx4.3.2实例操作:基于旧域名跳转到新域名后面加目录
(1)修改主配置文件

文章插图

文章插图
(2)重启服务并创建网页文件

文章插图

文章插图

文章插图
(3)添加映射关系并使用浏览器访问测试

文章插图
本机测试:

文章插图

文章插图
4.4基于参数匹配的跳转4.4.1 基于参数匹配的跳转的步骤
访问http://www.fzr.com/100-(100|200)-100.html 跳转到http://www.fzr.com页面
vim /usr/local/nginx/conf/nginx.confserver { listen 80; server_name www.fzr.com; #域名修改 charset utf-8; access_log /var/log/nginx/fzr.kgc.com-access.log; if ($request_uri ~ ^/100-(100|200)-(\d+).html$) { rewrite (.*) http://www.fzr.com permanent; } location / { root html; index index.html index.htm; }systemctl restart nginx解释:$request_uri: 包含请求参数的原始URI , 不包含主机名,如: http://www.fzr.com/abc/bbs/index.html?a=1&b=2中的/abc/bbs/index.php?a=1&b=2$uri:这个变量指当前的请求URI,不包括任何参数,如: /abc/bbs/index.html$document_uri: 与$uri相同,这个变量指当前的请求URI,不包括任何传递参数 , 如:/abc/bbs/index.html
用浏览器访问 http://www.fzr.com/100-200-100.html 或 http://www.fzr.com/100-100-100.html 跳转到http://www.fzr.com页面
推荐阅读
- C语言指针重点
- 第2-2-4章 常见组件与中台化-常用组件服务介绍-分布式ID-附Snowflake雪花算法的代码实现
- 【ASP.NET Core】MVC控制器的各种自定义:应用程序约定的接口与模型
- 文明与征服2022钓鱼达人活动图文攻略
- 剑与远征奇境探险海螺奇妙夜通关路线图攻略
- 闪耀暖暖归人与过客完美搭配套装选择攻略
- 2022蚂蚁庄园8月9日答案最新
- iQOOZ5与RealmeQ3s哪个好_iQOOZ5与RealmeQ3s选哪个
- 我的世界漏斗与漏斗之间怎么相连(我的世界漏斗上怎么放东西)
- 图学习【参考资料2】-知识补充与node2vec代码注解