nginx调优操作之nginx隐藏其版本号

1.nginx下载

  下载网址:nginx.org

2.解压nginx

[root@iZwz9cl4i8oy1reej7o8pmZ soft]# ls
nginx-1.10.3.tar.gz
[root@iZwz9cl4i8oy1reej7o8pmZ soft]# tar xf nginx-1.10.3.tar.gz 

3.修改源码

[root@iZwz9cl4i8oy1reej7o8pmZ soft]# ls
nginx-1.10.3  nginx-1.10.3.tar.gz
#进入nginx源码包 [root@iZwz9cl4i8oy1reej7o8pmZ soft]# cd nginx
-1.10.3 [root@iZwz9cl4i8oy1reej7o8pmZ nginx-1.10.3]# ls auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src [root@iZwz9cl4i8oy1reej7o8pmZ nginx-1.10.3]#

  修改nginx.h文件

[root@iZwz9cl4i8oy1reej7o8pmZ nginx-1.10.3]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@iZwz9cl4i8oy1reej7o8pmZ nginx-1.10.3]# cd src/core/
[root@iZwz9cl4i8oy1reej7o8pmZ core]# vim nginx.h 
[root@iZwz9cl4i8oy1reej7o8pmZ core]# 

  修改后如下:

  8 #ifndef _NGINX_H_INCLUDED_
  9 #define _NGINX_H_INCLUDED_
 10 
 11 
 12 #define nginx_version      1010003      
 13 #define NGINX_VERSION      "0.0.1"            #NGINX对外显示的版本号
 14 #define NGINX_VER          "LiWang/" NGINX_VERSION   #NGINX对外显示的服务器名
 15 
 16 #ifdef NGX_BUILD
 17 #define NGINX_VER_BUILD    NGINX_VER " (" NGX_BUILD ")"
 18 #else
 19 #define NGINX_VER_BUILD    NGINX_VER
 20 #endif
 21 
 22 #define NGINX_VAR          "NGINX"
 23 #define NGX_OLDPID_EXT     ".oldbin"
 24 
 25 
 26 #endif /* _NGINX_H_INCLUDED_ */

  修改ngx_http_special_response.c内容

#进入src/http文件夹下
[root@iZwz9cl4i8oy1reej7o8pmZ http]# pwd
/root/soft/nginx-1.10.3/src/http
#利用vim编辑ngx_http_special_response.c文件 [root@iZwz9cl4i8oy1reej7o8pmZ http]# vim ngx_http_special_response.c
 #修改结果如下
14 static ngx_int_t ngx_http_send_error_page(ngx_http_request_t *r, 15 ngx_http_err_page_t *err_page); 16 static ngx_int_t ngx_http_send_special_response(ngx_http_request_t *r, 17 ngx_http_core_loc_conf_t *clcf, ngx_uint_t err); 18 static ngx_int_t ngx_http_send_refresh(ngx_http_request_t *r); 19 20 21 static u_char ngx_http_error_full_tail[] = 22 "<hr><center>" NGINX_VER "Server:LiWang blog:www.cnblogs.com/wang-li</center>" CRLF 23 "</body>" CRLF 24 "</html>" CRLF 25 ; 26 27 28 static u_char ngx_http_error_tail[] = 29 "<hr><center>nginx</center>" CRLF 30 "</body>" CRLF 31 "</html>" CRLF 32 ;

  编辑vim ngx_http_header_filter_module.c 文件

[root@iZwz9cl4i8oy1reej7o8pmZ http]# pwd
/root/soft/nginx-1.10.3/src/http
[root@iZwz9cl4i8oy1reej7o8pmZ http]# vim ngx_http_header_filter_module.c 

  修改结果如下

 47 
 48 
 49 static char ngx_http_server_string[] = "Server: LiWang" CRLF;
 50 static char ngx_http_server_full_string[] = "http://www.cnblogs.com/wang-li" NGINX_VER CRLF;
 51 
 52 
 53 static ngx_str_t ngx_http_status_lines[] = {
 54 
 55     ngx_string("200 OK"),
 56     ngx_string("201 Created"),
 57     ngx_string("202 Accepted"),
 58     ngx_null_string,  /* "203 Non-Authoritative Information" */
 59     ngx_string("204 No Content"),
 60     ngx_null_string,  /* "205 Reset Content" */
 61     ngx_string("206 Partial Content"),
 62 
 63     /* ngx_null_string, */  /* "207 Multi-Status" */
 64 
 65 #define NGX_HTTP_LAST_2XX  207
 66 #define NGX_HTTP_OFF_3XX   (NGX_HTTP_LAST_2XX - 200)

4.开始进行源码编译

  安装必要的插件

[root@iZwz9cl4i8oy1reej7o8pmZ nginx-1.10.3]# yum install -y pcre pcre-devel zlib zlib-devel

  添加nginx用户

[root@iZwz9cl4i8oy1reej7o8pmZ nginx-1.10.3]# useradd nginx -s /sbin/nologin 
[root@iZwz9cl4i8oy1reej7o8pmZ nginx-1.10.3]# tail -n 1 /etc/passwd
nginx:x:500:500::/home/nginx:/sbin/nologin

  开始进行编译

[root@iZwz9cl4i8oy1reej7o8pmZ nginx-1.10.3]# ./configure --prefix=/usr/local/nginx-1.10 --user=nginx --group=nginx

  出现如下信息则为制作ok

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using builtin md5 code
  + sha1 library is not found
  + using system zlib library

  nginx path prefix: "/usr/local/nginx-1.10"
  nginx binary file: "/usr/local/nginx-1.10/sbin/nginx"
  nginx modules path: "/usr/local/nginx-1.10/modules"
  nginx configuration prefix: "/usr/local/nginx-1.10/conf"
  nginx configuration file: "/usr/local/nginx-1.10/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx-1.10/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx-1.10/logs/error.log"
  nginx http access log file: "/usr/local/nginx-1.10/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

  开始make and make install

[root@iZwz9cl4i8oy1reej7o8pmZ nginx-1.10.3]# make && make install

5.开始配置

  配置参照网址:

  http://www.cnblogs.com/wang-li/p/6689615.html

  配置过后进行访问

[root@iZwz9cl4i8oy1reej7o8pmZ conf]# curl -I www.wang-li.top:1234
HTTP/1.1 200 OK
Server: LiWang
Date: Tue, 11 Apr 2017 14:11:03 GMT
Content-Type: text/html
Content-Length: 560
Last-Modified: Sun, 26 Mar 2017 13:51:24 GMT
Connection: keep-alive
ETag: "58d7c75c-230"
Accept-Ranges: bytes

[root@iZwz9cl4i8oy1reej7o8pmZ conf]# 
欢迎转发! 请保留源地址: https://www.cnblogs.com/NoneID
原文地址:https://www.cnblogs.com/NoneID/p/6696673.html