修改nginx服务器类型

http://tech.foolpig.com/2010/06/01/nginx-version/

网络转载,通常nginx服务器不隐藏服务器类型及版本信息
curl -I http://10.60.30.23

HTTP/1.1 200 OK
Server: nginx nginx/0.8.53
Date: Tue, 14 Dec 2010 08:10:06 GMT
Content-Type: text/html
Content-Length: 151
Last-Modified: Mon, 13 Dec 2010 09:39:55 GMT
Connection: keep-alive
Accept-Ranges: bytes 

这对于服务器安全来说是个隐患,用以下方法可以改善这种情况
1. 编辑源代码../src/core/nginx.h

/*
 * Copyright (C) Igor Sysoev
 */


#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_


#define nginx_version      1000004
#define NGINX_VERSION      "1.0.4"
#define NGINX_VER          "nginx/" NGINX_VERSION

#define NGINX_VAR          "NGINX"
#define NGX_OLDPID_EXT     ".oldbin"


#endif /* _NGINX_H_INCLUDED_ */


修改
#define NGINX_VERSION      "10001212"
#define NGINX_VER          "我自己的服务器/" NGINX_VERSION


然后编译安装。这样是侧地的改变了服务器的信息。

2. 编辑/usr/local/nginx/conf/nginx.conf,添加

server_tokens off;

重新启动nginx
/usr/local/nginx/sbin/nginx -s reload

最终结果如下
curl -I http://10.60.30.23

HTTP/1.1 200 OK
Server: pws 1.0
Date: Tue, 14 Dec 2010 08:24:32 GMT
Content-Type: text/html
Content-Length: 151
Last-Modified: Mon, 13 Dec 2010 09:39:55 GMT
Connection: keep-alive
Accept-Ranges: bytes 

你可能感兴趣的:(nginx)