CentOS 7 安裝 Nginx 與修改伺服器版本資訊
阿新 • • 發佈:2019-04-07
本文編寫於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