当前位置:首页 > Web开发 > 正文

host拒绝非法请求

2024-03-31 Web开发

标签:

通过http_host字段拒绝非法请求

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

代码如下:

server { server_name ; 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拒绝非法请求

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/42417.html