nginx优化
1、隐藏版本号
进入nginx.conf
在http块中修改隐藏,不再server中,也不是location
server_tokens off;
2、日志分割
apache是自带日志分割的,按天来进行收集日志
nginx没有自带分割功能,脚本来实现日志分割
3、cpu绑定
4、连接超时
5、页面压缩
支持压缩的类型:
gzip_types text/plain text/javascript application/x-javascript text/css text/xml application/xml application/xml+rss image/jpg image/jpeg image/png image/gif application/x-httpd-php application/javascript application/json;
6、页面缓存时间
主要针对动态页面,图片的缓存
7、time_wait状态的回收
time_wait是tcp连接当中的一种状态。出现四次挥手之后,处于等待状态,双方不再发送数据
time_wait所占用的系统资源很小,数量比较少,完全可以忽略不计。但是太多了就有一定的影响
连接断开(四次挥手)之后,尽快的把time_wait状态的连接进行回收
netstat -n | awk '/^tcp/ {++s[$NF]} END {for (a in s) print a s[a]} :统计当前系统
在系统内核文件中进行设置:
vim /etc/sysctl.conf
防盗链
配置nginx.conf文件
在location模块中做以下配置:
步骤:
网页准备:
Web源主机(192.168.233.10)配置:
cd /usr/local/nginx/html
将game.jpg、error.png文件传到/usr/local/nginx/html目录下
vim index.html
清空所有内容然后添加
< img src="game.jpg"/>
</body>
</html>
做主机映射
echo "192.168.233.10 www.xy102.com" >> /etc/hosts
echo "192.168.233.20 www.xy103.com" >> /etc/hosts
盗链网站主机(192.168.233.20):
cd /usr/local/nginx/html
vim index.html
清空所有内容然后添加
< img src="http://www.xy102.com/game.jpg"/>
</body>
</html>
做本地映射
echo "192.168.233.10 www.xy102.com" >> /etc/hosts
echo "192.168.233.20 www.xy103.com" >> /etc/hosts
在盗图网站(20)主机上进行浏览器验证
http://www.xy103.com