-
地址重写
-
步骤一:修改配置文件
-
1)修改Nginx服务配置:
[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)重新加载配置文件
[root@svr5 ~]# /usr/local/nginx/sbin/nginx -s reload
3)创建网页目录以及对应的页面文件:
[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
步骤二:客户端测试
客户端使用浏览器测试各个页面的访问是否被重定向。
[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