nginx页面优化

发布于:2023-07-20 01:2715人浏览
对版本号进行更改的目的:可以根据nginx的版本号进行破译,因此都会隐藏后端服务应用的真实版本号

1.版本号

对版本号进行更改的目的:可以根据nginx的版本号进行破译,因此都会隐藏后端服务应用的真实版本号


1.1 查看版本号

#使用本地服务地址查询

curl -I 192.168.245.110

HTTP/1.1 200 OK

Server: nginx/1.12.2

Date: Sun, 25 Jun 2023 01:46:29 GMT

Content-Type: text/html

Content-Length: 612

Last-Modified: Wed, 21 Jun 2023 14:23:30 GMT

Connection: keep-alive

ETag: "649307e2-264"

Accept-Ranges: bytes

#使用nginx命令查询

nginx -v

nginx version: nginx/1.12.2



1.2 修改版本号

1.2.1 修改配置文件

#切换到nginx的配置文件目录下

cd /usr/local/nginx/

cd conf/

#复制配置文件做备份

cp nginx.conf nginx.conf.bak.2023.6.25

vim nginx.conf

#关闭版本号

在http中添加server_tokens off;



#重启服务

systemctl restart nginx.service


1.2.2 修改源码文件,重新编译安装

#切换到配置文件的目录

cd /opt/nginx-1.12.2/src/core/

#进入配置文件,将配置文件的真是版本号进行修改

vim nginx.h

#define NGINX_VERSION      "whd"


#重新编译安装

cd /opt/nginx-1.12.2/

#编译安装

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

make && make install

#修改配置文件

cd /usr/local/nginx/conf/

vim nginx.conf

#在源码包中重新定义了版本号,则打开版本号并无影响

在http中将off需改为on打开server_tokens on;


 systemctl restart nginx.service


相关文章
    最新文章
    热门标签