① 参考配置操作
(1)编辑 nginx.conf 配置文件
将 error_log 前的“#”去掉,记录缺点日志

将 access_log 前的“#”去掉,记录访问日志
(2)设置 access_log,修正配置文件如下:
log_format formatname '$remote_addr - $remote_user [$time_local] '
' \"大众$request\"大众 $status $body_bytes_sent \"大众$http_referer\"大众 '
' \"大众$http_user_agent\"大众 \"大众$http_x_forwarded_for\公众'; access_log
logs/access.log formantname; #formatname 是设置配置文件格式的名称
② 备注事变查看 nginx.conf 配置文件中,error_log、access_log 前的“#”是否去掉
0x02 做事
1 限定 IP 访问
对网站或敏感目录的访问 IP 进行限定
① 参考配置操作
(1)修正配置文件
#vi /usr/local/nginx/conf/nginx.conf
详细设置如下:
location / {
deny 192.168.1.1; #谢绝 IP
allow 192.168.1.0/24; #许可 IP
allow 10.1.1.0/16; #许可 IP
deny all; #谢绝其他所有 IP
(2)重新启动 nginx 做事
② 备注事变
根据运用处景,设置得当的 IP 地址,检讨配置文件 #more /usr/local/nginx/conf/nginx.conf 中的 server 项
2 掌握超时时间
掌握超时时间,提高做事器性能,降落客户真个等待韶光
① 建议配置
client_body_timeout 10; #设置客户端要求主体读取超时时间
client_header_timeout 10; #设置客户端要求头读取超时时间
keepalive_timeout 5 5; #第一个参数指定客户端连接保持活动的超时时间,第二个参数是可选的,它指定了头保持活动的有效韶光
send_timeout 10; #指定相应客户真个超时时间
须要根据运用处景的须要选择得当的参数值。
1 、符合性剖断依据
超时后,做事器返回相应的。
2 、参考检测方法
检讨配置文件 #more /usr/local/nginx/conf/nginx.conf
3 下载限定并发和速率
限定客户端下载速率,担保做事器负载正常
① 建议配置
例如网站存放路径为/usr/local/nsfocus/ ,做事器名称为:down.nsfocus.com
limit_zone one $binary_remote_addr 10m;
server
{
listen 80;
server_name down.nsfocus.com;
index index.html index.htm index.PHP;
oot /usr/local/nsfocus;
#Zone limit;
location / {
limit_conn one 1;
limit_rate 20k;
}
………
下载时,不会超过设计的并发连接数和速率限定,同时检讨 nginx.conf 文件中的配置
0x03 其他事变
1 卸载不须要的模块
卸载不须要的 nginx 模块, 最大限度地将 nginx 加载的模块最小化
① 建议配置
(1)检讨须要禁用的模块
在编译 nginx 做事器时,利用下面的命令查看哪些模块该当启用,哪些模应
该禁用:
# ./configure --help | less
一旦处选了要禁用的模块,须要与干系职员沟通确认,并经由测试不影响业
务运行。
(2)例如,要禁用 autoindex 和 SSI 模块,命令如下:
# ./configure --without-http_autoindex_module --without-http_ssi_module
# make
# make install
② 备注事变
Nginx 不包含不必要的模块或者输入 ./configure --help | less 进行检讨
2 防盗链设置
防止其他网站盗链本网站资源
location ~ ^.+\.(gif|jpg|png|swf|flv|rar|zip)$ {
valid_referers none blocked server_names .nsfocus.com
http://localhost baidu.com;
if ($invalid_referer) {
rewrite ^/ [img]http://www.nsfocus.com/images/default/logo.gif[/img];
# return 403;
根据运用处景,设置得当的域名
从造孽网站访问所保护的资源,涌现设置的页面。同时检讨配置文件 #more /usr/local/nginx/conf/nginx.conf
3 自定义缺点信息
1)修正 src/http/ngx_http_special_response.c,自己定制缺点信息
## messages with just a carriage return.
static char ngx_http_error_400_page = CRLF;
static char ngx_http_error_404_page = CRLF;
static char ngx_http_error_413_page = CRLF;
static char ngx_http_error_502_page = CRLF;
static char ngx_http_error_504_page = CRLF;
常见缺点:
400 bad request
404 NOT FOUND
413 Request Entity Too Large
502 Bad Gateway
504 Gateway Time-out
URL 地址栏中输入 http://ip:8800/manager12345,访问出错时,返回自定义的缺点页面
4 隐蔽 nginx 做事信息头
① 建议配置
修正 nginx解压路径/src/http/ngx_http_header_filter_module.c文件的第48
和 49 行内容,自定义头信息:
static char ngx_http_server_string = “Server:XXXXX.com” CRLF;
static char ngx_http_server_full_string = “Server:XXXXX.com” CRLF;
添加如下代码到 nginx.conf 配置文件,禁止缺点页面中显示 nginx 版本号:
server_tokens off
② 备注事变
做事信息头显示设置的内容,检讨 http 做事信息头内容
5 补丁更新
安装系统补丁,修补漏洞
1 、参考配置操作
手动安装补丁或安装最新版本软件,所安装的补丁,应首先在经由测试验证;安装前,要做好数据备份。
2查看版本和编译器信息
欢迎大家分享更好的思路^^_^^ !
关注301在路上"大众年夜众号
带你学习带你飞~~