好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

nginx常用if判断语句与变量set使用方法

[root@www conf]#  tail      nginx.conf
location  /  {
    stub_status  on;
access_log      off;
}
}
include    vhost/*.conf;              //指定虚拟主机配置文件路径
 }
 [root@www conf]#  cd      /usr/local/nginx/conf/vhost
 编辑虚拟主机配置文件
 [root@www vhost]#vim      dedecms.conf  
 server {
 listen              80;
 server_name    www.wokao.com;
 index      index.html    index.htm   index.php;
 root    /data/www/wokao;
 location  ~  .*\.(php|php5)?$
 {
 Include    test.conf;
 fastcgi_pass    unix:/tmp/php-cgi.sock;
 #fastcgi_pass    127.0.0.1:9000;
 fastcgi_index  index.php;
 include  fcgi.conf;
 }
 }
 [root@www conf]#  pwd
 /usr/local/nginx/conf
 [root@www conf]#  vim    test.conf
 //如果访问request的method值为POST则返回“o”
 If    ($request_method    ~*   "POST")
 {
 set    $test  o;
 }
 if    ($remote_addr      =     '188.188.3.171')        //如果访问地址等于188.188.3.171则返回“k”
 同理
 #if  ($remote_addr    !=   '188.188.3.171')        //如果访问地址非188.188.3.171则返回“k”
 {
 Set    $test    "${test}k";
 }
 //如果满足上述条件则返回“ok”处理方式为返回403
 if    (  $test    =    ok  )
 {
 Return    403;
 #rewrite    ^(.*)   http://www.fengyuba.com  permanent;
 #如果满足条件则重定向到www.fengyuba.com
 }

查看更多关于nginx常用if判断语句与变量set使用方法的详细内容...

  阅读:69次