1)首先要下载nginx包这里以1.12.2为例;

2)安装nginx所需的支持包

yum install -y gcc gcc-c++ pcre-devel zlib-devel

3)创建nginx用户

useradd -M -s /sbin/nologin nginx

4)解压nginx并配置

tar zxf nginx-1.12.2.tar.gz

①vi src/core/nginx.h    13行     
          #define nginx_version      1010002
      #define NGINX_VERSION      "6.12.62"         #此行修改的是你想要的版本号
      #define NGINX_VER          "MidServer/" NGINX_VERSION    
                                                                   #此行修改的是你想修改的软件名称

            ![](https://s1.51cto.com/images/blog/201901/08/dcb7f60989243494cb5e2351d441433f.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

            ②# vim src/http/ngx_http_special_response.c    29行

      #static u_char ngx_http_error_tail[] =
      "
MidServer
" CRLF "" CRLF "" CRLF ![](https://s1.51cto.com/images/blog/201901/08/d987ac49b6e40902f928e25f5d6f6cb5.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

5)yum -y install pcre openssl

  cd  nginx-1.12.2/

        # ./configure --prefix=/usr/local/nginx   --user=nginx --group=nginx \

--with-file-aio \
--with-http_ssl_module \
--ith-http_realip_module \
--ith-http_sub_module \
--ith-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre

make && make install

6)安装完后我们启动服务

 

/usr/local/nginx/sbin/nginx 启动服务

/usr/local/nginx/sbin/nginx -s stop 停止服务

 

测试是否隐藏了版本和软件名

 # curl -I 192.168.80.100
HTTP/1.1 200 OK
Server: MidServer/6.12.62
Date: Tue, 08 Jan 2019 07:36:11 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 08 Jan 2019 07:34:45 GMT
Connection: keep-alive
ETag: "5c345295-264"
Accept-Ranges: bytes

 

我们拿浏览器进行错误代码测试: