企业级Nginx Web服务优化

1、隐藏Nginx版本号

当服务器出错时,有时候就会暴露服务器类型及版本,一旦该版本存在漏洞,网站就会存在被攻击的危险。此时我们可以通过隐藏服务器信息方式,或给出其他类型服务器来保护服务器。

通过curl -I localhost 可以查看服务器版本信息

修改配置文件nginx.conf 在http标签段加入server_tokens  off;

重启nginx,再次执行curl -I localhost

2、更改源码隐藏nginx软件名及版本号

软件厂商处于品牌以及产片展示等原因,不允许在配置文件里进行修改,但是我们可以通过修改nginx软代码的方式达到目的。

(1)打开 

vim /usr/local/software/nginx-1.12.0/src/core/nginx.h

(2)打开vim /usr/local/software/nginx-1.12.0/src/http/ngx_http_header_filter_module.c,修改第49行的nginx。

(3)打开 vim /usr/local/software/nginx-1.12.0/src/http/ngx_http_special_response.c 修改红色标记处的内容。

三、更改nginx默认用户

nginx默认会使用nobody用户,通常我会建立nginx用户 useradd nginx -s /sbin/nologin -M,然后修改nginx.conf :user nginx ;

或者在编译nginx软件是指定编译的用户和组:

./configure --user=nginx --group=nginx  --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

(四)开启高效文件传输模式

设置参数:sendfile on;

sendfile参数用于开启文件高效传输模式。同时将tcp_nopush和tcp_nodelay两个指令设置为on,可防止网络及磁盘I/o阻塞,提升Nginx工作效率。

原文地址:https://www.cnblogs.com/fukai-blog/p/6962098.html