阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

149次阅读
没有评论

共计 5243 个字符,预计需要花费 14 分钟才能阅读完成。

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

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计5243字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中