不管是互联网企业还是传统企业,大多数喜欢使用NGINX作为反向代理,然后不合理的使用会存在一些安全隐患,下面介绍一些常用隐患处理方法。
隐藏应用服务器名称
修改NGINX源将,将SERVER名称换成X-WEB(此处自定义)
vim src/http/ngx_http_header_filter_module.c #
static char ngx_http_server_string[] = "Server: X-Web" CRLF;
static char ngx_http_server_full_string[] = "Server:X-Web" NGINX_VER CRLF;
vim src/http/ngx_http_special_response.c #将源代码的nginx更换成X-Web
static u_char ngx_http_error_tail[] =
"<hr><center>X-Web</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;
隐藏NGINX版本号
vim conf/nginx.conf
server_tokens off;
限制可用方法
限定请求方法,只支持GET和POST
vim conf/nginx.conf
location / {
if ($request_method !~* GET|POST) {
return 403;
}
proxy_pass http://XXXXX;
}