nginx基本安全优化
一、调整参数隐藏nginx软件版本号信息
查看nginx版本信息:
[root@nginx conf]# curl -I 192.168.200.102
HTTP/1.1 200 OK
Server: nginx/1.8.1 #这里显示了nginx的版本号即软件名称;
Date: Fri, 31 Aug 2018 09:20:47 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 31 Aug 2018 08:41:19 GMT
Connection: keep-alive
ETag: "5b88ff2f-264"
Accept-Ranges: bytes
隐藏nginx版本号只需要在nginx.conf文件中的http标签段内加入“server_tokens off”参数即可。
server_tokens参数的官方说明如下:
syntax: server_tokens on | off; #此行为参数语法,on为开启状态,off为关闭状态;
default: server_tokens on; #此行意思是不配置改参数,软件默认情况的结果;
context: http,server,location #此行为server_tokens参数可以放置的位置;
参数作用:激活或禁止nginx的版本信息显示在报错信息和server的响应首部位置中;
Enables or disables emitting of nginx version in error messages and inter"Server" response header field. #此行是参数的原文作用;
官方资料地址:
操作如下:
[root@nginx conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server_tokens off; #加入这一行即可;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
再次查看,nginx的版本信息就隐藏了:
[root@nginx conf]# systemctl reload nginx [root@nginx conf]# curl -I 192.168.200.102
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 31 Aug 2018 09:34:16 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 31 Aug 2018 08:41:19 GMT
Connection: keep-alive
ETag: "5b88ff2f-264"
Accept-Ranges: bytes
二、更改源码隐藏nginx软件名
建议在编译安装前修改,安装后修改软件名,需要重新编译。
第一步:依次修改3个nginx源码文件:
修改nginx.h文件
路径为:nginx源码包下面的 src/core/nginx.h 修改后如下:
...
#define NGINX_VERSION "1.0"
#define NGINX_VER "Web" NGINX_VERSION
...
#define NGINX_VAR "Web"
... 修改ngx_http_header_filter_module.c文件
路径为:nginx源码包下面的 src/http/ngx_http_header_filter_module.c 修改第49行,修改后如下:
static char ngx_http_server_string[] = "Server: Web" CRLF;
也可以 通过sed替换修改,命令如下:
sed -i '49 $#nginx#Web#g' ngx_http_header_filter_module.c 修改ngx_http_header_filter_module.c文件
路径为:nginx源码包下面的 src/http/ngx_http_header_filter_module.c
修改后如下:
第22行:"<hr><center>Web</center>" CRLF
第29行:"<hr><center>Web</center>" CRLF
第二步:修改后编译软件使其生效(如果是已经安装好的,需要重新编译。)
systemctl stop nginx ./configure --user=www --group=www --prefix=/application/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module make && make install systemctl start nginx [root@nginx nginx-1.8.1]# curl -I 192.168.200.102
HTTP/1.1 200 OK
Server: Web #服务名称和版本号已隐藏;
Date: Fri, 31 Aug 2018 15:00:46 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 31 Aug 2018 08:41:19 GMT
Connection: keep-alive
ETag: "5b88ff2f-264"
Accept-Ranges: bytes
三、更改nginx服务的默认用户
查看nginx服务对应的默认用户,一般情况下,nginx服务启动后,默认使用的用户是nobody,查看默认的配置文件,如下:
[root@nginx conf]# grep '#user' nginx.conf.default
#user nobody;
更改nginx的默认用户,操作如下:
一、为nginx服务建立新用户
[root@nginx conf]# useradd www -s /sbin/nologin -M
[root@nginx conf]# id www
uid=1002(www) gid=1002(www) 组=1002(www) 二、配置nginx服务,让其使用刚建立的nginx用户
第一种为直接更改配置文件参数,将默认的#user nobody;改为如下内容:
user nginx nginx 第二种方法为直接在编译nginx软件是指定编译的用户和组,命令如下:
./configure --user=www --group=www --prefix=/application/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module 三、检查更改用户的效果
[root@nginx conf]# ps -ef |grep nginx|grep -v frep
root 7360 1 0 23:00 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
www 7362 7360 0 23:00 ? 00:00:00 nginx: worker process
root 7416 1271 0 23:16 pts/0 00:00:00 grep --color=auto nginx
通过查看更改后的nginx进程,可以看到worker processes进程对应的用户都变成了nginx。当然,nginx的主进程还是以root身份运行的,后面的文章中会有更改root主进程服务用户的深度安全优化与架构技巧。
nginx基本安全优化的更多相关文章
- Nginx并发访问优化
Nginx反向代理并发能力的强弱,直接影响到系统的稳定性.安装Nginx过程,默认配置并不涉及到过多的并发参数,作为产品运行,不得不考虑这些因素.Nginx作为产品运行,官方建议部署到Linux64位 ...
- Nginx 之六: Nginx十万并发优化
操作 操作 Nginx 之六: Nginx十万并发优化
- Nginx配置性能优化与压力测试webbench【转】
这一篇我们来说Nginx配置性能优化与压力测试webbench. 基本的 (优化过的)配置 我们将修改的唯一文件是nginx.conf,其中包含Nginx不同模块的所有设置.你应该能够在服务器的/et ...
- nginx错误界面优化和日志管理
nginx错误界面优化 在进行web访问的时候,经常会遇到网站打不开报错的情况,nginx默认的界面并不美观,我们可以通过重定向到自定义的错误页面,提升用户体验,比如淘宝的错误页面还有商品信息和广告. ...
- Nginx web服务优化 (一)
1.Nginx基本安全优化 a.更改配置文件参数隐藏版本 编辑nginx.conf配置文件增加参数,实现隐藏Nginx版本号的方式如下.在nginx配置文件nginx.conf中的http标签段内加入 ...
- nginx web服务优化
nginx基本安全优化 1. 调整参数隐藏nginx软件版本号信息 软件的漏洞和版本有关,我们应尽量隐藏或消除web服务对访问用户显示各类敏感信息(例如web软件名称及版本号等信息),这样恶意的用户就 ...
- Linux实战教学笔记38:企业级Nginx Web服务优化实战(下)
四,Nginx站点目录及文件URL访问控制 4.1 根据扩展名限制程序和文件访问 Web2.0时代,绝大多数网站都是以用户为中心多的,例如:bbs,blog,sns产品,这几个产品都有一个共同特点,就 ...
- Linux实战教学笔记37:企业级Nginx Web服务优化实战(上)
一,Nginx基本安全优化 1.1 调整参数隐藏Nginx软件版本号信息 一般来说,软件的漏洞都和版本有关,这个很像汽车的缺陷,同一批次的要有问题就都有问题,别的批次可能就都是好的.因此,我们应尽量隐 ...
- 企业级Nginx Web服务优化实战
web优化一览总结表 优化类型 优化说明 优化方法 安全优化 隐藏nginx版本信息优化 修改nginx配置文件实现优化 server_tokens off: 修改nginx版本信息优化 修改ngin ...
- nginx 服务器并发优化
apache 提供的 ab 可以对服务器进行压力测试, 安装 ab: apt-get install apache2-utils 安装完后,ab 在目录 /usr/bin/ 下的. 执行: ab ...
随机推荐
- [Leetcode]003. Longest Substring Without Repeating Characters
https://leetcode.com/problems/longest-substring-without-repeating-characters/ public class Solution ...
- Codeforces Round #562 (Div. 2) A.Circle Metro
链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...
- II play with GG(思维规律)
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 IG won the S champion ...
- jQuery基础(2)
jQuery的属性操作,使用jQuery操作input的value值,jQuery的文档操作 零.昨日内容回顾 jQuery 宗旨:write less do more 就是js的库,它是javasc ...
- 丝滑顺畅:使用CSS3获取60FPS动画
原文链接: Smooth as Butter: Achieving 60 FPS Animations with CSS3 在移动端使用动画元素是很容易的. 如果你能遵循我们的这里的提示, 在移动端适 ...
- NET Core 2.0 介绍和使用
NET Core 2.0 特性介绍和使用指南 阅读目录 前言 特性概述 使用指南 .NET Core 2.0和1.0/1.1之间的关系 .NET CORE Rumtime改进 .NET Core SD ...
- CodeForces 731C C - Socks 并查集
Description Arseniy is already grown-up and independent. His mother decided to leave him alone for m ...
- Funsioncharts 线图 破解
在线示例:http://jsfiddle.net/henley/xnozyLa8/2/ 下载:http://files.cnblogs.com/files/ycdx2001/chart.zip
- c# 串口操作
public class CommPort : IDisposable { public string Port = ""; ///<summary> ///波特率96 ...
- 【踩坑】springMVC 接收String参数没有判断为空
今天在调试iReview项目的接口时,发现新增词条和新增库的时候,某些字段即使留空POST到后台时也能当做不为空. 经过排查,发现后台是使用 String 变量名 == null 这样的语句去判断变量 ...