你好,游客 登录 注册 搜索
背景:
阅读新闻

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

[日期:2017-10-22] 来源:Linux社区  作者:wang-li [字体: ]

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.linuxidc.com/Linux/2017-10/147892.htm

  配置过后进行访问

[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]# 

下面关于Nginx的文章您也可能喜欢,不妨参考下:

Nginx 403 forbidden的解决办法  http://www.linuxidc.com/Linux/2017-08/146084.htm

CentOS 7下Nginx服务器的安装配置  http://www.linuxidc.com/Linux/2017-04/142986.htm

CentOS上安装Nginx服务器实现虚拟主机和域名重定向  http://www.linuxidc.com/Linux/2017-04/142642.htm

CentOS 6.8 安装LNMP环境(Linux+Nginx+MySQL+PHP)  http://www.linuxidc.com/Linux/2017-04/142880.htm

Linux下安装PHP环境并配置Nginx支持php-fpm模块  http://www.linuxidc.com/Linux/2017-05/144333.htm

Nginx服务的SSL认证和htpasswd认证  http://www.linuxidc.com/Linux/2017-04/142478.htm

Ubuntu 16.04上启用加密安全的Nginx Web服务器  http://www.linuxidc.com/Linux/2017-07/145522.htm

Linux中安装配置Nginx及参数详解  http://www.linuxidc.com/Linux/2017-05/143853.htm

Nginx日志过滤 使用ngx_log_if不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

CentOS 7.2下Nginx+PHP+MySQL+Memcache缓存服务器安装配置  http://www.linuxidc.com/Linux/2017-03/142168.htm

CentOS6.9编译安装Nginx1.4.7  http://www.linuxidc.com/Linux/2017-06/144473.htm

Nginx 的详细介绍请点这里
Nginx 的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-10/147893.htm

linux
相关资讯       Nginx隐藏版本号 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款