赞
踩
一.Nginx跳转
1.跳转的作用和特点
1)跳转的作用
方便管理员对网站进行临时维护
2)Nginx跳转的特点
支持网站重定向
方便业务调整
方便故障维护
2.Nginx跳转实现的方式
1)rewrite进行匹配跳转
根据用户输入的内容匹配正则表达式进行跳转
2)使用if匹配全局变量后跳转
使用条件判断,满足条件进行跳转
3)使用location匹配在跳转
用户访问nginx网站根目录匹配正则表达式后跳转
3.配置跳转所在的位置
1)rewrite应用的位置
在Nginx配置文件的Server{}中
2)if判断
保存在Nginx配置文件网站根目录
if{}
3)Location
卸载nginx配置文件中的虚拟主机根中
4.正则表达式元字符类型
1)^ 匹配字符串开始位置
$ 匹配字符串结束位置
2)创建错误页面
[root@centos01 ~]# mkdir /error
[root@centos01 ~]# echo “www.error.com” > /error/error.html
失败页面
成功页面
3)客户端访问测试
www.benet.com
4.当用户访问www.benet.com/upload/index.php跳转到www.accp.com域名的主页上
1)修改nginx主配置文件
[root@centos01 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.benet.com;
charset utf8;
#access_log logs/host.access.log main;
location / {
root /code/;
index index.html index.php;
}
location ~* /upload/.*.php$ {
rewrite (.+) http://www.accp.com/ permanent;
}}
server {
listen 80;
server_name www.accp.com;
location / {
root /accp/;
index index.html;
}}}
2)创建benet.com目录
[root@centos01 ~]# mkdir /code/upload/
[root@centos01 ~]# echo “www.benet.com.php” > /code/upload/index.php
3)创建accp.com目录
[root@centos01 ~]# mkdir /accp
[root@centos01 ~]# echo “www.accp.com” > /accp/index.html
修改hosts文件
4)客户端访问
http://www.benet.com/upload/index.php
测试页面
测试成功!
感谢观看!拜拜ヾ(•ω•`)o啊
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。