Nginx优化与防盗链相关配置
一、隐藏 Nginx版本号
(一)如何隐藏Nginx版本号
1、在生产环境中,需要隐藏Ngnx的版本号,以避免安全漏洞的泄漏
2、查看方法
——使用fiddler工具在 Windows客户端查看 Nginx版本号
——在 Centos系统中使用“curl -I 网址”命令查看Nginx版本号
3、nginx隐藏版本号的方法
——修改配置文件法
——修改源码法
(二)隐藏Nginx版本号配置命令
方法一:
Nginx的配置文件中的 server_tokens选项的值设置为off
vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server_tokens off; ##添加,关闭版本号
}
systemctl restart nginx
curl -I http://192.168.200.50/ ##查看版本号
方法二:
修改源码文件,重新编译安装
vim /opt/nginx-1.12.0/src/core/nginx.h
#define nginx_version 1012000
#define NGINX_VERSION "1.0.0" #将原始的1.12.0修改为1.0.0
#define NGINX_VER "IIS" NGINX_VERSION #将原始的Nginx修改为IIS
#重新编译安装
cd /opt/nginx-1.12.0
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make && make install
#将方法一中关闭的版本号重新打开
vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server_tokens on; #打开
#重启服务
systemctl restart nginx.service
#查看版本号是否隐藏
curl -I http://192.168.200.50/
二、修改用户与组
vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; #将前面的#注释掉,然后修改用户与组为nginx
worker_processes 1;
systemctl restart nginx.service
ps aux