新产品为了效果,做的比较炫,用了很多的图片和JS,所以前端的性能是很大的问题,分篇记录前端性能优化的一些小经验。
第一篇: index.htm;
expires 5d;
}
# 因JS,CSS改动比较频繁,客户端缓存8小时
location ~* ^.+.(js|css)$ {
root /usr/local/resource/;
access_log off;
index index.html index.htm;
expires 8h;
}
# 其他静态资源
location / {
root /usr/local/resource;
access_log off;
expires 8h;
}
}
3、nginx 反向代理设置
# 反向代理服务,绑定域名www.abc.com
server {
listen 80;
server_name www.abc.com;
charset utf-8;
# BBS使用Discuz!
# 因反向代理为了提高性能,一部分;
access_log off;
index index.php;
# 转发host的信息,如果不设置host,在后台使用request.getServerName()取到的域名不是www.abc.com,而是127.0.0.1
proxy_set_header Host $host;
# 因Discuz! 为了安全,需要获取客户端User-Agent来判断每次POST数据是否跟第一次请求来自同1个浏览器,
# 如果不转发User-Agent,Discuz! 提交数据就会报"您的请求来路不正确,无法提交"的错误
proxy_pass_header User-Agent;
proxy_pass ;
access_log off;
index index.jsp;
proxy_pass ;
location = /50x.html {
root html;
}
}
nginx详细配置参考:http://wiki.nginx.org/
PS:如果安装提示GCC not found,运行下面命令安装就可以(apt-get install build-essential),仅限debian