资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
因tomcat处理静态资源的速度比较慢,所以首先想到的就是把所有静态资源(JS,CSS,image,swf)提到单独的服务器,用更加快速的HTTP服务器,这里选择了nginx了,nginx相比apache,更加轻量级,配置更加简单,而且nginx不仅仅是高性能的HTTP服务器,还是高性能的反向代理服务器。目前很多大型网站都使用了nginx,新浪、网易、QQ等都使用了nginx,说明nginx的稳定性和性能还是非常不错的。1. nginx 安装(linux)http:/nginx.org/en/download.html 下载最新稳定版本根据自己需要的功能先下载对应模板,这里下载了下面几个模块:openssl-0.9.8l,zlib-1.2.3,pcre-8.00编译安装nginx:1. ./configure 2. -without-http_rewrite_module 3. -with-http_ssl_module 4. -with-openssl=././lib/openssl-0.9.8l 5. -with-zlib=././lib/zlib-1.2.3 6. -with-pcre=././lib/pcre-8.00 7. -prefix=/usr/local/nginx 8. 9. make 10. 11. makeinstall2、nginx处理静态资源的配置1. #启动GZIP压缩CSS和JS 2. gzipon; 3. #压缩级别1-9,默认是1,级别越高压缩率越大,当然压缩时间也就越长 4. gzip_comp_level4; 5. #压缩类型 6. gzip_typestext/cssapplication/x-javascript; 7. 8. #定义静态资源访问的服务,对应的域名:res.abc.com 9. server 10. listen80; 11. server_nameres.abc.com; 12. 13. #开启服务器读取文件的缓存, 14. open_file_cachemax=200inactive=2h; 15. open_file_cache_valid3h; 16. open_file_cache_errorsoff; 17. 18. charsetutf-8; 19. 20. #判断如果是图片或swf,客户端缓存5天 21. location*.+.(ico|gif|bmp|jpg|jpeg|png|swf)$ 22. root/usr/local/resource/; 23. access_logoff; 24. indexindex.htmlindex.htm; 25. expires5d; 26. 27. 28. #因JS,CSS改动比较频繁,客户端缓存8小时 29. location*.+.(js|css)$ 30. root/usr/local/resource/; 31. access_logoff; 32. indexindex.htmlindex.htm; 33. expires8h; 34. 35. 36. #其他静态资源 37. location/ 38. root/usr/local/resource; 39. access_logoff; 40. expires8h; 41. 42. 3、nginx 反向代理设置1. #反向代理服务,绑定域名www.abc.com 2. server 3. listen80; 4. server_namewww.abc.com; 5. 6. charsetutf-8; 7. 8. #BBS使用Discuz! 9. #因反向代理为了提高性能,一部分http头部信息不会转发给后台的服务器, 10. #使用proxy_pass_header和proxy_set_header把有需要的http头部信息转发给后台服务器 11. location/bbs/ 12. roothtml; 13. access_logoff; 14. indexindex.php; 15. #转发host的信息,如果不设置host,在后台使用request.getServerName()取到的域名不是www.abc.com,而是127.0.0.1 16. proxy_set_headerHost$host; 17. #因Discuz!为了安全,需要获取客户端User-Agent来判断每次POST数据是否跟第一次请求来自同1个浏览器, 18. #如果不转发User-Agent,Discuz!提交数据就会报您的请求来路不正确,无法提交的错误 19. proxy_pass_headerUser-Agent; 20. proxy_passhttp:/127.0.0.1:8081; 21. 22. 23. #其他请求转发给tomcat 24. location/ 25. roothtml; 26. access_logoff; 27. indexindex.jsp; 28. proxy_passhttp:/127.0.0.1:8080; 29. 30. 31. error_page500502503504/50x.html; 32. location=/50x.html 33. roothtml; 34. 35. nginx详细配置参考:http:/wiki.nginx.org/PS:如果安装提示GCC not found,运行下面命令安装就可以(apt-get install build-essential),仅限debian
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号