Nginx优化与防盗链
文章目录
一、隐藏版本号
可以使用 Fiddler 工具抓取数据包,查看 Nginx版本,也可以在 CentOS 中使用命令 curl -I http://192.168.2.8显示响应报文首部信息。
curl -I http://192.168.2.8
方法一:修改配置文件方式
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.2.8
方法二:修改源码文件,重新编译安装
vim /opt/nginx-1.12.0/src/core/nginx.h
#define NGINX_VERSION "1.0.0" #修改版本号
#define NGINX_VER "IIS/" NGINX_VERSION #修改服务器类型
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.2.8
二、修改用户与组
方法一:编译安装时可指定,不再演示。见我上篇博客。
cd /opt/nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make && make install
nginx进程的属主
方法二:
vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; #取消注释,修改用户为 nginx ,组为 nginx
systemctl restart nginx
ps -ef | grep nginx 或ps aux | grep nginx
主进