nginx 根据目录指定root_nginx安全优化与性能优化

1.1 Nginx优化分类

安全优化(提升网站安全性配置)

性能优化(提升用户访问网站效率)

1.2 Nginx安全优化

1.2.1 隐藏nginx版本信息优化

官方配置参数说明:http://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens

官方参数:

Syntax: server_tokens on | off | build | string; #后面这俩参数收费的

Default: server_tokens on;

Context: http, server, location

配置举例:

[root@web01 ~]# cat /application/nginx/conf/nginx.conf

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile off;

keepalive_timeout 65;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

server {

listen 80;

server_name www.nmtui.com;

server_tokens off;

location / {

root html/www;

index index.html index.htm;

}

access_log logs/access_www.log main;

}

}

测试结果:

[root@web01 ~]# curl -I 10.0.0.8

HTTP/1.1 200 OK

Server: nginx

Date: Wed, 01 Nov 2017 18:32:40 GMT

Content-Type: text/html

Content-Length: 10

Last-Modified: Wed, 25 Oct 2017 01:20:56 GMT

Connection: keep-alive

ETag: "59efe6f8-a"

Accept-Ranges: bytes

1.2.2 修改nginx版本信息

修改版本信息需要修改程序源文件信息

修改内核信息

[root@web01 nginx-1.10.2]# vim src/core/nginx.h

# ···

13 #define NGINX_VERSION "6.6.6" #修改版本号

14 #define NGINX_VER "george/" NGINX_VERSION #web软件名

22 #define NGINX_VAR "georgekai"

# ···

修改头部信息

[root@web01 nginx-1.10.2]# vim src/http/ngx_http_header_filter_module.c

# ···

49 static char ngx_http_server_string[] = "Server: george" CRLF;

# ···

修改错误页显示

[root@web01 nginx-1.10.2]# vim src/http/ngx_http_special_response.c

# ···

# 此处可以不修改

21 static u_char ngx_http_error_full_tail[] =

22 "


" NGINX_VER "
" CRLF

23 "

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值