-
地址重写
-
步骤一:修改配置文件
-
1)修改Nginx服务配置:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18[root@svr5 ~]# vim /usr/local/nginx/conf/nginx.conf .. .. server { listen 80; server_name www.tarena.com; location / { root html; index index.html index.htm; rewrite ^/ http://bbs.tarena.com/; #重写,访问www.tarena.com将被重定向至bbs.tarena.com rewrite ^/image/(.*)$ /picture/$1 break; #有访问/image目录下资源的请求,重定向至/picture目录 if ($http_user_agent ~* url) { #识别客户端curl浏览器 rewrite ^(.*)$ /curl/$1 break; } } }
2)重新加载配置文件
复制代码
1
2[root@svr5 ~]# /usr/local/nginx/sbin/nginx -s reload
3)创建网页目录以及对应的页面文件:
复制代码
1
2
3
4
5[root@svr5 ~]# mkdir -p /usr/local/nginx/html/curl/picture [root@svr5 ~]# echo "I am is curl page" > /usr/local/nginx/html/curl/test.html [root@svr5 ~]# cp /usr/share/backgrounds/gnome/Road.jpg > /usr/local/nginx/curl/picture/test.jpg
步骤二:客户端测试
客户端使用浏览器测试各个页面的访问是否被重定向。
复制代码
1
2
3
4[root@svr5 ~]# curl http://192.168.4.5/test.html [root@svr5 ~]# firefox http://192.168.4.5/test.html [root@svr5 ~]# firefox http://192.168.4.5/images/test.jpg
最后
以上就是曾经向日葵最近收集整理的关于LNMP地址重写的全部内容,更多相关LNMP地址重写内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复