首页 > 其他 > 详细

nginx使用总结

时间:2014-11-24 20:58:23      阅读:256      评论:0      收藏:0      [点我收藏+]

nginx主页:http://nginx.org/

nginx for windows:http://nginx.org/en/docs/windows.html

学习nginx:http://wiki.nginx.org/GettingStarted

以下为location的demo,汇总常见配置以及它们的对比:

demo1(匹配度由低到高):

#1    
location / {
   return 500;
}
#2
location /a/ {
    return 404;
}
#3
location ~* \.jpg$ {
    return 403;
}
#4
location ^~ /a/ {
    return 402;
}
#5
location  /a/1.jpg {
    return 401;
}
#6
location = /a/1.jpg {
    return 400;
}

demo2(关于安全性):

location ~* \.php$ {
    proxy_pass http://www.baidu.com; 
}
location ^~ /upload/ {
  if ($request_filename ! ~* \.(jpg|jpeg|gif|png|swf|zip|rar|txt)$) {
  return 403;
   }
   alias   /home/www/html/upload/;
}

demo3(正则按顺序匹配):

location ~* \.jpg$ {
        return 402;
}
location ~* 1\.jpg$ {
        return 403;
}


nginx使用总结

原文:http://my.oschina.net/wnjustdoit/blog/348282

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!