隐藏NGINX服务器名称 和版本号
隐藏NGINX服务器名称:
修改或隐藏服务器名称需要修改源码nginx.h,nginx.h在src/core/目录下 。具体操作如下:
把下面两个宏的值修改为自己设定的值,例如"NGX"。 都改为 "" 即隐藏名称。
1:
#define NGINX_VER "nginx/" NGINX_VERSION 改为 #define NGINX_VER "NGX" NGINX_VERSION
#define NGINX_VAR "NGINX" 改为 #define NGINX_VAR "NGX"
2:
同理改版本号修改NGINX_VERSION的值
#define NGINX_VERSION "1.8.0"
修改如下: [root@python core]# cat nginx.h
/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
*/
#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_
#define nginx_version 1000001
#define NGINX_VERSION "0.0.1"
#define NGINX_VER "LYS/" NGINX_VERSION
#ifdef NGX_BUILD
#define NGINX_VER_BUILD NGINX_VER " (" NGX_BUILD ")"
#else
#define NGINX_VER_BUILD NGINX_VER #endif
#define NGINX_VAR "LYS"
#define NGX_OLDPID_EXT ".oldbin"
#endif /* _NGINX_H_INCLUDED_ */
[root@salt nginx]# curl -I 192.168.50.100
HTTP/1.1 403 Forbidden
Server: LYS/0.0.1
Date: Mon, 12 Dec 2016 16:15:41 GMT
Content-Type: text/html
Content-Length: 166
Connection: keep-alive
[root@salt nginx]#
隐藏NGINX版本号:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server_tokens off; #添加这一行内容即可