Nginx优化之一
Nginx优化之一
安全优化、性能优化、日志优化。
一、Nginx安全优化
1.1:隐藏nginx版本信息
官方配置参数说明: server_tokens on | off | build | string;Default: server_tokens on;Context: server, location
配置举例:
[root@node1 ~]# cat /etc/nginx/nginx.confuser nginx;worker_processes 1;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events { worker_connections 1024;}{ include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$' '"$"$ access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; server_tokens off;65; #gzip on; include /etc/nginx/conf.d/*.conf;}
测试结果:
[root@node1 ~]# curl -I localhostHTTP/1.1 200Server: nginx09 May 2018 02:38:56 GMTContent-Type: text/htmlContent-Length: 11Last-Modified: Wed, 09 May 2018 02:29:10 GMTConnection: keep-aliveETag: "5af25cf6-b"Accept-Ranges: bytes
1.2:修改nginx版本信息
修改版本信息需要修改程序源文件信息
修改内核信息:
[root@node1 nginx-1.10.2]# vim src/core/nginx.h# ··· 13 #define NGINX_VERSION "1.0" 14 #define NGINX_VER "clsn/" NGINX_VERSION 22 #define NGINX_VAR "clsn"# ···
修改头部信息:
[root@node1 nginx-1.10.2]# vim src/# ··· 49 static char ngx_= "Server: clsn" CRLF;# ···
修改错误页显示:
[root@noode1 nginx-1.10.2]# vim src/# ···# 此处可以不修改 21 static u_char ngx_= 22 "