Nginx服务器拒绝非GET方式请求保障安全性

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; Linux学习,http:// linux.it.net.cn
deny all;
}
if ($request_filename ~ /test/index.html) {
# return 404;
rewrite ^/(.*) /index.html; }; Linux学习,http:// linux.it.net.cn
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,这样的目录下面无脚本执行权限,从而防止非法用户上传脚本得到webshell
nginx上也很简单,我们使用location 如下:
location ~ ^/upload/.*\.(php|php5)$
{
deny all;
}
其中upload换为你要设置的目录名字
这条规则的含义是匹配请求连接中开头是/upload/,中间匹配任意字符,结尾匹配.php或者.php5的页面,最后利用deny all禁止访问,这样就防止了上传目录的脚本执行权限

参考:[url]http://linux.it.net.cn/e/server/nginx/2015/0110/11642.html[/url]
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值