zoukankan      html  css  js  c++  java
  • 实用 nginx.conf 用法大全

    服务器拒绝非GET方式请求保障安全性,因为 DELETE、POST、PUT 是可以修改数据的。

    Nginx 解决方案

    在 nginx.conf 配置文件的网站配置区域中添加如下代码片段:

    非 GET 类型请求,则返回 403 状态码。

    if ($request_method !~* GET) {
        return 403;
    }
    

    非 GET 或 POST 类型请求,则返回 403 状态码。

    if ($request_method !~* GET|POST) {
        return 403;
    }
    

    或另一种写法:

    if ($request_method !~ ^(GET|POST)$) {
        return 403;
    }
    

    Apache 解决方案

    在站点配置文件 .htaccess 中添加如下代码片段:

    非 GET 或 POST 类型请求,则返回 403 状态码。

    <Location />
        <LimitExcept GET POST>
            Order Allow,Deny
            Deny from all
        </LimitExcept>
    </Location>
    

    IIS 解决方案

    在站点 web.config 配置文件的 节点下添加如下代码:

    只允许开启 GET、POST、HEAD 请求方法

    <system.webServer>
        <security>
            <requestFiltering>
                <verbs allowUnlisted="false">
                    <add verb="GET" allowed="true"/>
                    <add verb="POST" allowed="true"/>
                    <add verb="HEAD" allowed="true"/>
                </verbs>
            </requestFiltering>
        </security>
    </system.webServer>
    
    文章来自:chenxuhua.com
  • 相关阅读:
    2019.8.15刷题统计
    2019.8.12刷题统计
    2019.8.11刷题统计
    2019.8.10刷题统计
    2019.8.9刷题统计
    2019.8.8刷题统计
    2019.8.7刷题统计
    2019.8.6刷题统计
    xuezhan.org 6.28
    xuezhan.org 6.27
  • 原文地址:https://www.cnblogs.com/chenxuhua/p/12613419.html
Copyright © 2011-2022 走看看