Nginx安全&&调优

本文详细介绍了Nginx的安全配置和性能优化措施,包括隐藏版本号、修改运行用户、调整进程数、设置最大打开文件数、启用高效传输模式、设置连接超时时间、限制文件上传大小、Fastcgi的使用、gzip模块的配置、目录访问控制、身份验证以及访问次数限制等,旨在提升服务器的安全性和效率。
摘要由CSDN通过智能技术生成
Nginx安全&&调优
1、隐藏版本号
编译前修改源码
[root@study nginx-1.16.1]# vim src/core/nginx.h 	
更改如下行即可
 13 #define NGINX_VERSION      "1.16.1"
 14 #define NGINX_VER          "nginx/" NGINX_VERSION

[root@study nginx-1.16.1]# vim src/http/ngx_http_header_filter_module.c 
修这一行Server:后的名称即可
 49 static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
2、修改用户
[root@study ~]# vim /usr/local/nginx/conf/nginx.conf
 user  nginx;
[root@study ~]# useradd -M -s /sbin/nologin nginx
[root@study ~]# /usr/local/nginx/sbin/nginx -s reload
[root@study ~]# lsof -i :80
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   7890  root    6u  IPv4  38505      0t0  TCP *:http (LISTEN)
nginx   7942 nginx    6u  IPv4  38505      0t0  TCP *:http (LISTEN)

3、修改nginx运行个数(Nginx运行进程个数一般我们设置CPU的核心或者核心数x2)
[root@study ~]# vim /usr/local/nginx/conf/nginx.conf
3 worker_processes  1;-->worker_processes  4;
[root@study ~]# /usr/local/nginx/sbin/nginx -s reload
[root@study ~]# lsof -i :80
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   7890  root    6u  IPv4  38505      0t0  TCP *:http (LISTEN)
nginx   7947 nginx    6u  IPv4  38505      0t0  TCP *:http (LISTEN)
nginx   7948 nginx    6u  IPv4  38505      0t0  TCP *:http (LISTEN)
nginx   7949 nginx    6u  IPv4  38505      0t0  TCP *:http (LISTEN)
nginx   7950 nginx    6u  IPv4  38505      0t0  TCP *:http (LISTEN)
4、nginx最大打开的文件数
添加:
worker_rlimit_nofile 102400;	#这个指令是指当一个nginx进程打开的最多文件描述符数目,
events {
     use epoll;		#IO多路复用
     worker_connections  102400;
 }
select,poll,epoll都是IO多路复用的机制。I/O多路复用就通过一种机制,可以监视
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值