您的位置:首页 > 技术中心 > 运维 >

怎么安装并调优Nginx

时间:2023-05-20 13:10


怎么安装并调优Nginx

Nginx编译前的优化

[root@linuxprobe ~]# wget http://nginx.org/download/nginx-1.10.1.tar.gz[root@linuxprobe ~]# tar xvf nginx-1.10.1.tar.gz -C /usr/local/src/[root@linuxprobe ~]# cd /usr/local/src/nginx-1.10.1/

编译前的优化主要是用来修改程序名等等,例如:

[root@linuxprobe nginx-1.10.1]# curl -I http://www.baidu.com……Server: bfe/1.0.8.14……[root@linuxprobe nginx-1.10.1]# curl -I http://www.sina.com.cn……Server: nginx……[root@linuxprobe nginx-1.10.1]# curl -I https://www.linuxprobe.comHTTP/1.1 200 OKServer: nginx/1.10.1 #我们目标是将nginx更改名字Content-Type: text/html; charset=UTF-8Connection: keep-aliveX-Powered-By: PHP/5.6.29Set-Cookie: PHPSESSID=smm0i6u4f9v7bj0gove79ja1g7; path=/Cache-Control: no-cacheDate: Mon, 07 Seq 2016 06:09:11 GMT[root@linuxprobe nginx-1.10.1]# vim src/core/nginx.h

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

#define NGINX_VERSION “nginx_stable” #此行修改的是你想要的版本号

#define NGINX_VER “linuxprobe/” NGINX_VERSION #此行修改的是你想修改的软件名称

[root@linuxprobe nginx-1.10.1]# vim +49 src/http/ngx_http_header_filter_module.c

修改HTTP头信息中的connection字段,防止回显具体版本号

拓展:通用http头域

通用头域包含请求和响应消息都支持的头域,通用头域包含Cache-Control、 Connection、Date、Pragma、Transfer-Encoding、Upgrade、Via。如果通用头域被扩展,双方都需要支持此扩展。如果存在不支持的通用头域,一般会当作实体头域来处理。一些设备或软件能够获取连接信息,而另一些则不能,如果要完全隐藏,就必须做全面的保密

static char ngx_http_server_string[] = “Server: LinuxprobeWeb” CRLF;

[root@linuxprobe nginx-1.10.1]# vim +29 src/http/ngx_http_special_response.c

定义了http错误码的返回

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

static u_char ngx_http_error_full_tail[] ="" NGINX_VER "" CRLF"

以上就是怎么安装并调优Nginx的详细内容,更多请关注Gxl网其它相关文章!

本类排行

今日推荐

热门手游