本文编写于2019-4-7。当前最新稳定版本为1.14.2。

首先安装编译依赖软件。修改服务器软件信息直接往下看。

[root@promote ~]# yum install -y gcc gcc-c++ autoconf antomake vim net-tools
[root@promote ~]# yum install -y zlib zlib-devel openssl openssl-devel pcre pcre-devel
#添加nginx用户 不允许本地账号登录
[root@promote ~]# useradd -s /sbin/nologin -M nginx
#解压文件
[root@promote ~]# tar -xvf nginx-1.14.2.tar.gz
#
[root@promote ~]# cd nginx-1.14.2
#检查依赖和生成makefile文件
[root@promote ~]# ./configure --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-pcre
#安装软件
[root@promote ~]# make && make install

启动nginx,查看端口信息。

[root@promote ~]# whereis nginx
nginx: /usr/local/nginx
[root@promote ~]# cd /usr/local/nginx/sbin/
[root@promote sbin]# ls
nginx
[root@promote sbin]# ./nginx
#查看nginx版本
[root@promote sbin]# ./nginx -v
nginx version: nginx/1.14.2
[root@promote sbin]# netstat -ntlp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13088/nginx: master
[root@promote sbin]# netstat -ntlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13088/nginx: master 

重新编译安装nginx并启动。修改后信息如下

[root@promote ~]# cd /root/
[root@promote ~]# cd nginx-1.14.2
#修改13-14行
[root@promote nginx-1.14.2]# vim src/core/nginx.h
#修改后结果
#修改版本为9.0.17,服务器软件为Tomcat
[root@promote nginx-1.14.2]# sed -n '13, 14p' src/core/nginx.h
#define NGINX_VERSION      "9.0.17"
#define NGINX_VER          "Tomcat/" NGINX_VERSION
[root@promote nginx-1.14.2]#
[root@promote nginx-1.14.2] vim src/http/ngx_http_header_filter_module.c
#修改src/http/ngx_http_header_filter_module.c
#修改后结果
[root@promote nginx-1.14.2]# sed -n '49p' src/http/ngx_http_header_filter_module.c
static u_char ngx_http_server_string[] = "Server: Tomcat" CRLF;
#查看服务器信息
[root@promote nginx-1.14.2]# curl -I 192.168.126.134
HTTP/1.1 200 OK
Server: Tomcat/9.0.17
Date: Sun, 07 Apr 2019 14:17:31 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 07 Apr 2019 13:45:48 GMT
Connection: keep-alive
ETag: "5ca9ff0c-264"
Accept-Ranges: bytes

[root@promote nginx-1.14.2]#

04-08 05:50