
文章插图
(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
经验总结扩展阅读
- 2023食品科学与工程类热门专业有哪些 就业前景怎么样
- 2023自然保护与环境生态类热门专业有哪些 比较好的专业
- 2023公共卫生与预防医学类热门专业有哪些 比较好的专业
- 2023管理科学与工程类热门专业有哪些 比较好的专业
- 丙火与辛金灵魂伴侣 五行无克运势提升
- 练大腿的方法 练大腿的方法都有哪些
- 谁最喜欢甲木女 与丁火男白首不分离
- 甲木男喜欢女生类型 外在与内在并存
- 雄黄粉驱蛇怎么用
- 蒜薹与蒜苔哪个正确
