码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx 优化配置

时间:2018-08-19 11:52:36      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:bmp   优化   ash   date   none   ali   min   修改   fine   

nginx 优化配置
查看隐藏版本号:
curl -I http://192.168.106.138
HTTP/1.1 200 ok
Server:nginx/1.12.0
--------------------------------隐藏版本号方法 1-----------------------------------------
vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
....
}
----------------------------------------隐藏版本号方法 2 ---------------------------------------
vim /opt/nginx-1.12.0/src/core/nginx.h
#define NGINX_VERSION "1.12.0" 在编译安装之前就修改

--------------------------------------------缓存时间-------------------------------------
vim /usr/local/nginx/conf/nginx.conf
location ~.(gif|jpg|jepg|png|bmp|ico)$ {
root html;
expires 1d;
}
---------------------------------------------日志切割-----------------------------------
vim /opt/fenge.sh
chmod +x fenge.sh
脚本内容:结合周期 性计划任务
#!/bin/bash
#Filename:fenge.sh
d=$(date -d "-1 day" "+%y%m%d") #只显示一天前时间
logs_path="/var/log/nginx"
pid_path="/usr/local/nginx/logs/nginx.pid"
[ -d $logs_path ] || mkdir -p $logs_path
mv /usr/local/nginx/logs/access.log ${logs_path}/test.com-access.log-$d
kill -USR1 $(cat $pid_path)
find $logs_path -mtime +30 | xargs rm -rf

crontab -e
0 1 /opt/fenge.sh
---------------------------------超时设置------------------------------------------------
vim /usr/local/nginx/conf/nginx.conf
keepalive_timeout 65 180;
#180:客户端超时时间
#65:服务器超时时间
client_header_timeout 80;
#请求头部超时时间
client_body_timeout 80;
#body主体超时时间
#默认单位 “秒”
------------------------------------------更改进程数------------------------------------
cat /proc/cpuinfo | grep -c "physical" #CPU 核数
vim /usr/local/nginx/conf/nginx.conf
worker_processes 2
events {
worker_connections 4096;
}
ps aux | grep nginx #查看进程数量
--------------------------------网页压缩-----------------------------------------
vim /usr/local/nginx/conf/nginx.conf
添加如下内容:
gzip on;
gzip_buffers 4 64k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_min_length 1k;
gzip_vary on;
gzip_types text/plain text/javascript application/x-javascript text/csstext/xml application/xml application/xml+rss test/jpg test/png;
------------------------------------防盗链-------------------------------------------
vim /usr/local/nginx/conf/nginx.conf
添加如下内容:
location ~
.(jpg|gif|swf)$ {
valid_referers none blocked *.baidu.com baidu.com;
if ( $invalid_referer ) {
rewrite / http://www.baidu.com/error.png;
}
}
---------------------------------------fpm参数优化---------------------------------------------
pid = run/php-fpm.pid
pm = dynamic
pm.max_children=20
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8

Nginx 优化配置

标签:bmp   优化   ash   date   none   ali   min   修改   fine   

原文地址:http://blog.51cto.com/13746824/2161543

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!