nginx
https://nginx.org/
https://nginx.org/en/download.html

wget https://nginx.org/download/nginx-1.26.0.tar.gz

tar -zxvf nginx-1.26.0.tar.gz 
Nginx编译前的优化

 cd nginx-1.26.0/
curl -I http://www.baidu.com


curl -I http://www.baidu.com

Server: bfe/1.0.8.18


目的更改源码隐藏软件名称和版本号


vim src/core/nginx.h
#define nginx_version      1026000
#define NGINX_VERSION      "1.26.0"
#define NGINX_VER          "nginx/" NGINX_VERSION

#define nginx_version      1026000
#define NGINX_VERSION      "8.8"
#define NGINX_VER          "XWS/" NGINX_VERSION

修改HTTP头信息中的connection字段,防止回显具体版本号
vim src/http/ngx_http_header_filter_module.c


static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF;

static u_char ngx_http_server_string[] = "Server: XWS" CRLF;
static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF;


用头域包含请求和响应消息都支持的头域,通用头域包含Cache-Control(缓存控制)、 Connection(连接)、Date(日期)、Pragma(短语)、Transfer-Encoding(传输编码)、Upgrade(升级)、Via。对通用头域的扩展要求通讯双方都支持此扩展,如果存在不支持的通用头域,一般将会作为实体头域处理。那么也就是说有部分设备,或者是软件,能获取到connection,部分不能,要隐藏就要彻底!


这个文件定义了http错误码的返回,有时候我们页面程序出现错误,Nginx会代我们返回相应的错误代码,回显的时候,会带上nginx和版本号,我们把他隐藏起来

vim src/http/ngx_http_special_response.c

22 "<hr><center>" NGINX_VER "</center>" CRLF

22 "<hr><center>" "XWS" "</center>" CRLF

安装依赖包
yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel  pcre pcre-devel -y    


 ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre
 
 --with-http_dav_module          #启用支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)
                                    默认关闭,需要编译开启
--with-http_stub_status_module  #启用支持(获取Nginx上次启动以来的工作状态)
--with-http_addition_module         #启用支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求)
--with-http_sub_module              #启用支持(允许一些其他文本替换Nginx相应中的一些文本)
--with-http_flv_module              #启用支持(提供支持flv视频文件支持)
--with-http_mp4_module              #启用支持(提供支持mp4视频文件支持,提供伪流媒体服务端支持)
--with-pcre   #需要注意,这里指的是源码,用#./configure --help |grep pcre查看帮助



make -j 2 && make install 

cd  /usr/local/nginx

./sbin/nginx
/usr/local/nginx/sbin/nginx 
netstat -antup | grep nginx
curl  -I 192.168.40.131
iptables -F  

http://192.168.40.131/aaa.html