Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3049187
  • 博文数量: 535
  • 博客积分: 15788
  • 博客等级: 上将
  • 技术积分: 6507
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-07 09:11
文章分类

全部博文(535)

文章存档

2016年(1)

2015年(1)

2014年(10)

2013年(26)

2012年(43)

2011年(86)

2010年(76)

2009年(136)

2008年(97)

2007年(59)

分类: 系统运维

2010-09-16 13:24:23

可以试试nginx 的lua模块:

I've been doing a lot of configuration tweaking recently, due to some complex requirements for a virtual host I'm writing for a relaunch due later this month. As I came across a couple of gotchas and problems that required a lot of head scratching, googling and trawling through the , I thought I'd write a series of short posts to try and help any other folk that may have similar Nginx configuration problems in the future.

Multiple if statements

As Nginx doesn't allow multiple or nested if statements you can't do something like:

if ($request_method = POST && $http_cookie ~* "CCCC=.+(?:;|$)")

However, you can set variables and you can do if statements on variables
 so this can be rewritten:

if ($request_method = POST) {     set $test P;   }     if ($http_cookie ~* "CCCC=.+(?:;|$)" ) {     set $test "${test}C";   }     if ($test = PC) {     #rewrite rule goes here.   }

As you can use regular expressions on if statements this method allows you to do both && and | checks.

The example is taken from a hidden away example on the but as it took me ages to find hopefully it will help you to.


转自:


阅读(2166) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~