VPS侦探论坛

 找回密码
 注册
查看: 4626|回复: 6

军哥,您好,编程的问题。

[复制链接]
发表于 2013-7-9 11:10:22 | 显示全部楼层 |阅读模式

在conf文件里,我想同时满足二个条件
  1. if ( $http_user_agent ~* "compatible; MSIE 6.0; Windows NT 5.1; SV1;"|$ http_referer ~* "news") {

  2.               return 403;

  3.                 }
复制代码




禁止ie6的用户访问包含news关键词的url

同时满足这二个条件的才生效,但是我这样写报错。军哥能否帮我纠正一下。很重要。谢谢。
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2013-7-9 16:32:03 | 显示全部楼层


$http_referer是记录从哪个地址过来的
$request 才是用户访问的url

同时满足是与运算用&
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2013-7-10 13:57:30 | 显示全部楼层

军哥好,语法有错误。


  1. if ( $http_user_agent ~* "compatible; MSIE 6.0; Windows NT 5.1; SV1;" & $request  ~* "news") {

  2.               return 403;

  3.                 }
复制代码


这样写会报错,麻烦再帮我看看。
  1. /usr/local/nginx/sbin/nginx -t
  2. nginx: [emerg] unexpected "&" in /usr/local/nginx/conf/sitestar.conf:10
  3. nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
复制代码
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2013-7-10 20:53:56 | 显示全部楼层



if ( $http_user_agent ~* "compatible; MSIE 6.0; Windows NT 5.1; SV1;"  ) && ( $request  ~* "news" ) {
这样试试
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2013-7-11 17:05:27 | 显示全部楼层

军哥。改成这样还不行,麻烦再帮我看一下。万份感谢了啊。


  1. [root@li472-166 ~]# /etc/init.d/nginx   restart
  2. Restarting nginx daemon: nginxnginx: [emerg] invalid condition "$http_user_agent                      " in /usr/local/nginx/conf/sitestar.conf:10
  3. nginx already running.
复制代码


军哥。改成这样还不行,麻烦再帮我看一下。万份感谢了啊。

  1. if ( $http_user_agent ~* "compatible; MSIE 6.0; Windows NT 5.1; SV1;"  ) && ( $request  ~* "news" ) {

  2.                return http://www.weimeigu.com/tip/;

  3.                 }
复制代码

军哥运维代购:http://shop63846532.taobao.com/

发表于 2013-7-11 18:28:32 | 显示全部楼层

看了一下nginx的if判断貌似不支持与或运算也不支持if语句嵌套
那就
set $rule 0;
                if ($request  ~* ’news‘)
                {
                        set $rule "${rule}1";
                }
                if ($http_user_agent ~* 'MSIE 6')
                {
                       set $rule "${rule}2";
                }
                if ($rule = "012")
                {
                        deny all;
                }

这样试试看吧
 楼主| 发表于 2013-7-12 13:17:23 | 显示全部楼层

万份感谢了
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-24 19:22 , Processed in 0.027109 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表