当前位置: 首页 > news >正文

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/wang-li/p/6696673.html

相关文章:

  • 图片视频制作方法
  • Rsyslog日志服务搭建
  • 2017年北京下半年软考网上报名时间和网址
  • 各大搜索引擎智能提示API(jsonp实现跨域自动补全建议)
  • SpringMVC传入参数
  • Vue SSR 从入门到 Case Study
  • Android学习笔记进阶20 之得到图片的缩略图
  • 解决面板里没有network manager图标的问题 ,也就是在桌面环境下,没有那个网络图标...
  • python类的继承、封装和多态
  • SQLite 索引(Index)
  • java zip 压缩与解压
  • linux shell 命令获取字符串/文件的MD5值
  • Promise使用手册
  • C中的预编译宏定义
  • 电商技术解密之售后退货
  • 3.7、@ResponseBody 和 @RestController
  • Akka系列(七):Actor持久化之Akka persistence
  • EOS是什么
  • Mithril.js 入门介绍
  • Mybatis初体验
  • node.js
  • Python 反序列化安全问题(二)
  • ReactNative开发常用的三方模块
  • ucore操作系统实验笔记 - 重新理解中断
  • 产品三维模型在线预览
  • 分享一份非常强势的Android面试题
  • 技术攻略】php设计模式(一):简介及创建型模式
  • 快速体验 Sentinel 集群限流功能,只需简单几步
  • 排序算法学习笔记
  • 悄悄地说一个bug
  • 我的业余项目总结
  • 详解NodeJs流之一
  • 想晋级高级工程师只知道表面是不够的!Git内部原理介绍
  • 从如何停掉 Promise 链说起
  • #单片机(TB6600驱动42步进电机)
  • (2021|NIPS,扩散,无条件分数估计,条件分数估计)无分类器引导扩散
  • (4)事件处理——(7)简单事件(Simple events)
  • (bean配置类的注解开发)学习Spring的第十三天
  • (DFS + 剪枝)【洛谷P1731】 [NOI1999] 生日蛋糕
  • (WSI分类)WSI分类文献小综述 2024
  • (二开)Flink 修改源码拓展 SQL 语法
  • (附源码)计算机毕业设计高校学生选课系统
  • (三)mysql_MYSQL(三)
  • (译) 理解 Elixir 中的宏 Macro, 第四部分:深入化
  • (原創) 未来三学期想要修的课 (日記)
  • (转)winform之ListView
  • (轉)JSON.stringify 语法实例讲解
  • (轉貼) 2008 Altera 亞洲創新大賽 台灣學生成果傲視全球 [照片花絮] (SOC) (News)
  • .[backups@airmail.cc].faust勒索病毒的最新威胁:如何恢复您的数据?
  • .bashrc在哪里,alias妙用
  • .bat批处理(二):%0 %1——给批处理脚本传递参数
  • .cn根服务器被攻击之后
  • .NET / MSBuild 扩展编译时什么时候用 BeforeTargets / AfterTargets 什么时候用 DependsOnTargets?
  • .NET 表达式计算:Expression Evaluator
  • .NET 跨平台图形库 SkiaSharp 基础应用