码迷,mamicode.com
首页 > Web开发 > 详细

nginx通过http_host拒绝非法请求

时间:2019-11-29 09:22:46      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:请求头   var   查看   server   turn   list   cat   clu   nginx   

通过http_host字段拒绝非法请求

在nginx的运行过程中,查看日志会发现有很多请求并不是请求你的服务器,那么你应该注意了,有可能是非法请求,要拒绝这种请求就需要通过判断http_host来阻断请求。

代码如下:

server {
       server_name  www.test.com;
       listen       8888;
        if ($http_host !~ "www.test.com:8888")  {
        return 403;
        }
       include /etc/nginx/default.d/*.conf;
       location / {
       root /var/nginx/html;
       index index.php index.html index.htm;
       }
}

这样,就无法通过伪造请求头来请求你的服务器啦!

nginx通过http_host拒绝非法请求

标签:请求头   var   查看   server   turn   list   cat   clu   nginx   

原文地址:https://blog.51cto.com/11962757/2454576

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!