nginx调优

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx调优相关的知识,希望对你有一定的参考价值。

nginx安装

1.安装依赖库

yum -y install make gcc gcc-c++ glibc glibc-devel lsof   pcre pcre-devel  zlib zlib-devel  openssl openssl--devel

yum install pcre-devel pcre  zlib-devel zlib openssl-devel -y(也可以用这个依赖库)

2.下载源码包

3.解压  编译 安装

4. 启动

为什么要屏蔽nginx版本信息?

答:因为黑客可以扫描出nginx版本信息,可以查看对应版本信息的漏洞,然后对相应的版本信息进行攻击。

如何查看nginx版本信息?

答:curl -I +域名或者IP

[[email protected] nginx]# curl -I 127.0.0.1

HTTP/1.1 200 OK

Server: nginx/1.10.3     ###看出我使用的nginx是1.10版本的

Date: Tue, 25 Jul 2017 09:03:15 GMT

Content-Type: text/html

Content-Length: 612

Last-Modified: Tue, 25 Jul 2017 08:55:50 GMT

Connection: keep-alive

ETag: "59770796-264"

Accept-Ranges: bytes

修改nginx源码文件,然后重新编译安装,达到隐藏效果

5.修改源码文件

cd /root/nginx-1.10.3

第一个配置文件:vim src/core/nginx.h

1)#define NGINX_VERSION      "1.10.3"

改成

#define NGINX_VERSION      "8.8.8.8"  ###修改你想要的版本号

2)define NGINX_VER          "nginx/" NGINX_VERSION###修改你想要的软件名称

改成

define NGINX_VER          "test/" NGINX_VERSION

第二个配置文件:vim src/http/ngx_http_header_filter_module.c

static char ngx_http_server_string[] = "Server: nginx" CRLF;###修改HTTP头信息中的connection字段,防止回显具体版本号。

改成

static char ngx_http_server_string[] = "Server: test" CRLF;

第三个配置文件:vim src/http/ngx_http_special_response.c

"<hr><center>nginx</center>" CRLF###定义了http错误码的返回,当页面程序出现错误,nginx会代我们返回相应的代码,回显的时候,会带上版本号。(404页面)

改成

"<hr><center>test</center>" CRLF

6.由于改动源码,我们需要重新安装,上面已经讲过怎么安装这里不做叙述。


7.测试

[[email protected] nginx-1.10.3]# curl -I 127.0.0.1

HTTP/1.1 200 OK

Server: test/8.8.8.8

Date: Tue, 25 Jul 2017 09:30:19 GMT

Content-Type: text/html

Content-Length: 612

Last-Modified: Tue, 25 Jul 2017 09:29:17 GMT

Connection: keep-alive

ETag: "59770f6d-264"

Accept-Ranges: bytes

404 Not Found


test/8.8.8.8


本文出自 “帅小欣” 博客,请务必保留此出处http://jiaxinwang.blog.51cto.com/12273793/1950899

以上是关于nginx调优的主要内容,如果未能解决你的问题,请参考以下文章

Nginx调优

Nginx 性能调优

nginx安装以及调优

Nginx 调优

Nginx安装配置及调优

实战——Nginx调优