Nginx 以事件驱动(epoll)的方式编写,所以有非常好的性能,同时也是一个非常高效的反
向代理、负载平衡。但是 Nginx 并不支持 cgi 方式运行,原因是可以减少因此带来的一些程
序上的漏洞。所以必须使用 FastCGI 方式来执行 PHP 程序
由于 Nginx 本身的一些优点,轻量,开源,易用,越来越多的公司使用 nginx 作为自己公司
的 web 应用服务器,本文详细介绍 nginx 源码安装的同时并对 nginx 进行优化配置
编译前的优化主要是用来修改程序名等等,目的更改源码隐藏软件名称和版本号
[root@nginx ~]# yum -y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel
[root@nginx ~]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
[root@nginx ~]# tar zxf nginx-1.10.2.tar.gz
[root@nginx ~]# cd nginx-1.10.2/
[root@nginx nginx-1.10.2]# vim src/core/nginx.h
# 此行修改的是你想要的版本
#define NGINX_VERSION "1.10.2" # 第13行
# 此行修改的是你想修改的软件名称
#define NGINX_VER "nginx/" NGINX_VERSION # 第14行
修改上面的信息,即可更改 nginx 显示版本。例如:(curl –I 可看到,请求头和响应头显示)
#define NGINX_VERSION "7.0"
#define NGINX_VER "IIS/" NGINX_VERSION
修改 HTTP 头信息中的 connection 字段,防止回显具体版本号
拓展:
通用 http 头 ,通用头包含请求和响应消息都支持的头,通用头包含 Cache-Control、
Connection、Date、Pragma、Transfer-Encoding、Upgrade、Via。对通用头的扩展要求通讯双方都支持此扩展,如果存在不支持的通用头,一般将会作为实体头处理。那么也就是说有部分设备,或者是软件,能获取到 connection,部分不能,要隐藏就要彻底!
[root@nginx nginx-1.10.2]# vim src/http/ngx_http_header_filter_module.c
# 修改前
static char ngx_http_server_string[] = "Server: nginx" CRLF; # 第49行
# 修改后
static char ngx_http_server_string[] = "Server: IIS" CRLF;
定义了 http 错误码的返回:
有时候我们页面程序出现错误,Nginx 会代我们返回相应的错误代码,回显的时候,会带上
nginx 和版本号,我们把他隐藏起来
[root@nginx nginx-1.10.2]# vim src/http/ngx_http_special_response.c
# 修改前
static u_char ngx_http_error_tail[] =
"
nginx " CRLF # 第29行
"
" CRLF "