CentOS 7 安裝 Nginx 與修改服務器版本信息

本文編寫於2019-4-7。當前最新穩定版本爲1.14.2。html

首先安裝編譯依賴軟件。修改服務器軟件信息直接往下看。nginx

[root@promote ~]# yum install -y gcc gcc-c++ autoconf automake 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

未建立用戶報錯信息以下。c++

[root@promote keepalived]# cd /usr/local/nginx/sbin/
[root@promote sbin]# ls
nginx
[root@promote sbin]# ./nginx
nginx: [emerg] getpwnam("nginx") failed
[root@promote sbin]#

啓動nginx,查看端口信息。vim

[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]#
相關文章
相關標籤/搜索