| 
 | 
 
upstream tomcat { 
ip_hash; 
server 192.168.2.187:8080; 
} 
location ~* /html { 
if ($request_method = PUT ) { 
return 403; 
} 
if ($request_method = DELETE ) { 
return 403; 
} 
if ($request_method = POST ) { 
return 403; 
} 
proxy_method GET; 
proxy_pass http://tomcat; 
} 
当路径包含/html的时候,则代理到server后端进行请求数据。这里屏蔽了PUT,DELETE,POST方法,只是使用了GET,主要目的是为了安全性,因为DELETE,POST,PUT是可以修改数据的。 
或者: 
limit_except GET { 
allow 192.168.1.1; 
deny all; 
} 
if ($request_filename ~ /test/index.html) { 
# return 404; 
rewrite ^/(.*)/index.html;                                                                       }; 
nginx禁止访问txt|doc文件                              
方法一:全局设置,禁止访问任何以后缀txt|doc的文件 
       location ~* \.(txt|doc)$ { 
       deny all; 
       }方法二:只禁止访问某目录下的txt|doc 
       location ~* \.(txt|doc)$ { 
       if (-f $request_filename) { 
       root html/job; 
       break; 
        } 
   } 
nginx禁止某中浏览器访问:#浏览器类型可从日志得知。 
server 
      { 
              listen      80; 
              server_name  test.domain.com; 
              index index.php index.html; 
              root   /opt/nginx/html/; 
              if ( $http_user_agent ~* "MSIE 6.0" ) { 
              return 403; 
               } 
设置目录执行权限                                                                                 
在windows+iis下,可以设置上传目录,类似:upload,uploadfile,attachments,这样的目录下面无脚本执行权限,从而防止非法用户上传脚本得到webshellnginx上也很简单,我们使用location 如下: 
location ~ ^/upload/.*\.(php|php5)$ 
{ 
deny all; 
} 
其中upload换为你要设置的目录名字 
这条规则的含义是匹配请求连接中开头是/upload/,中间匹配任意字符,结尾匹配.php或者.php5的页面,最后利用denyall禁止访问,这样就防止了上传目录的脚本执行权限 |   
 
 
 
 |