标签:linux
nginx常见日志收集及分析工具有rsyslog,awstats,flume,elk,storm等
1 nginx location作用:
location指令的作用是可以根据用户请求的URL来执行不同的应用,就是根据用户请求的网站地址URL匹配,匹配成功即进行相关的操作。
2 location语法
location[=|`||`*|]
[root@web01 scripts]# cd /application/nginx/conf/
[root@web01 extra]# vim www.conf
server {
listen 80;
server_name www.etiantian.org etiantian.org;
location / {
return 401;
}
location = / {
return 402;
}
location /documents/ {
return 403;
}
location ^~ /images/ {
return 404;
}
location ~* \.(gif|jpg|jpeg)$ {
return 500;
}
#access_log logs/www_access.log main;
}[root@web01 extra]# /application/nginx/sbin/nginx -t nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful [root@web01 extra]# /application/nginx/sbin/nginx -s reload
加上注释172.16.1.8 web01 www.etiantian.org
[root@web01 extra]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.1.5 lb01 172.16.1.6 lb01 172.16.1.7 web02 172.16.1.8 web01 www.etiantian.org 172.16.1.51 de01 db01.etiantian.org 172.16.1.31 nfs01 172.16.1.41 backup 172.16.1.61 m01
[root@web01 extra]# ping www.etiantian.org -c4 PING web01 (172.16.1.8) 56(84) bytes of data. 64 bytes from web01 (172.16.1.8): icmp_seq=1 ttl=64 time=0.031 ms 64 bytes from web01 (172.16.1.8): icmp_seq=2 ttl=64 time=0.033 ms 64 bytes from web01 (172.16.1.8): icmp_seq=3 ttl=64 time=0.030 ms 64 bytes from web01 (172.16.1.8): icmp_seq=4 ttl=64 time=0.031 ms --- web01 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 2999ms rtt min/avg/max/mdev = 0.030/0.031/0.033/0.004 ms
curl 一下
[root@web01 extra]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.etiantian.org
402[root@web01 extra]# cp www.conf{,.test.location}把www.conf 中的402注释掉如下:
#location = / {
#return 402;
#}继续curl后出现结果如下:401
[root@web01 extra]# ../../sbin/nginx -s reload
[root@web01 extra]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.etiantian.org
401[root@web01 extra]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.etiantian.org/index.html
401
[root@web01 extra]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.etiantian.org/documents/document.html
403[root@web01 extra]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.etiantian.org/images/1.gif
404[root@web01 extra]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.etiantian.org/test/1.gif
500匹配顺序:
实战1:
配置好windowns客户端机的本地dns解析,然后输入地址:
http://www.etiantian.org/documents/ 报错:403
如何让不报403?让返回结果为其他地址呢?
[root@web01 extra]# vim
[root@web01 extra]# cat www.conf
server {
listen 80;
server_name www.etiantian.org etiantian.org;
location / {
return 401;
}
#location = / {
#return 402;
#}
location /documents/ {
root html/www; #403修改为指定的地址
index index.html; #403修改为指定的地址
}
location ^~ /images/ {
return 404;
}
location ~* \.(gif|jpg|jpeg)$ {
return 500;
}
#access_log logs/www_access.log main;
}[root@web01 extra]# ../../sbin/nginx -s reload [root@web01 extra]# cd ../../html/www/ [root@web01 www]# mkdir documents [root@web01 www]#cd documents/ [root@web01 www]# echo doc >index.html
windows 浏览器输入http://www.etiantian.org/documents/回车
这就说明设置成功了。
如果输入http://www.etiantian.org/就是报错默认的错误
本文出自 “sandshell” 博客,请务必保留此出处http://sandshell.blog.51cto.com/9055959/1958210
标签:linux
原文地址:http://sandshell.blog.51cto.com/9055959/1958210