Nginx与tomcat 实现负载均衡和动静分离
2015-12-07 12:12
666 查看
一 配置
1. nginx介绍就不多说了,我使用的是阿里云的centos ,使用yum命令安装 的,很容易。
2. nginx的配置文件:nginx.conf配置
我参考文章,点击查看
配置完成后 /usr/sbin/nginx -s reload 重新加载配置文件
二. 测试效果:
测试Nginx 和Tomcat高并发的情况下处理静态页面性能如何?
采用了 Linux ab网站压力测试命令来测试一下性能
ab -c 10 -n 1000表示同时处理100个请求并运行1000次index.html文件
1.测试一下Nginx 处理静态页面的性能
访问nginx的:
ab -c 10 -n 1000 http://www.lexinli.cn/index.html
每秒请求数结果:Requests per second: 7095.22 [#/sec] (mean)
直接访问tomcat的:
ab -c 10 -n 1000 http://www.lexinli.cn:8080/index.html
每秒请求数结果:Requests per second: 1675.85 [#/sec] (mean)
静态交给Nginx处理,动态请求交给Tomcat,提高了性能
1. nginx介绍就不多说了,我使用的是阿里云的centos ,使用yum命令安装 的,很容易。
2. nginx的配置文件:nginx.conf配置
我参考文章,点击查看
配置文件如下: # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes 1; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #负载均衡设置,暂时未用到,后面会使用到 upstream www.###.cn { #ip_hash; server 127.0.0.1:8080; } server { listen 80; server_name www.lexinli.cn; index index.html index.jsp; root /home/wwwftp/ROOT; #配置Nginx动静分离,定义的静态页面直接从Nginx发布目录读取。 location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ { root /home/wwwftp/ROOT; #expires定义用户浏览器缓存的时间为1天,如果静态页面不常更新,可以设置更长这样可以节省带宽和缓解服务器的压力 expires 1d; } #所有jsp、do的动态请求都交给后面的tomcat处理 location ~ (\.jsp)|(\.action)$ { #tomcat地址 proxy_pass http://127.0.0.1:8080; proxy_redirect off; proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } #location / { # proxy_connect_timeout 3; # proxy_send_timeout 30; # proxy_read_timeout 30; # proxy_pass http://www.lexinli.cn; # } } # Load config files from the /etc/nginx/conf.d directory # The default server is in conf.d/default.conf include /etc/nginx/conf.d/*.conf; }
配置完成后 /usr/sbin/nginx -s reload 重新加载配置文件
二. 测试效果:
测试Nginx 和Tomcat高并发的情况下处理静态页面性能如何?
采用了 Linux ab网站压力测试命令来测试一下性能
ab -c 10 -n 1000表示同时处理100个请求并运行1000次index.html文件
1.测试一下Nginx 处理静态页面的性能
访问nginx的:
ab -c 10 -n 1000 http://www.lexinli.cn/index.html
每秒请求数结果:Requests per second: 7095.22 [#/sec] (mean)
直接访问tomcat的:
ab -c 10 -n 1000 http://www.lexinli.cn:8080/index.html
每秒请求数结果:Requests per second: 1675.85 [#/sec] (mean)
静态交给Nginx处理,动态请求交给Tomcat,提高了性能
相关文章推荐
- 当发现user library中的lib没有部署到tomcat中的lib文件夹时的解决办法
- tomcat报错
- 简单读取TOMCAT的内存使用情况
- Tomcat中JVM内存溢出及合理配置
- Tomcat各组件关系及server.xml配置文件介绍
- window系统下的安装版tomcat安装过程
- Tomcat安装配置
- 安装配置java,tomcat,eclipse
- Eclipse和MyEclipse使用tomcat发布web项目时的区别
- Tomcat apr模式的安装方法
- 安装tomcat
- Linux CentOS Tomcat修改默认端口 -
- Jetty 的工作原理以及与 Tomcat 的比较
- godaddy 域名 绑定阿里云服务器 绑定tomcat (.fm的域名可以看看)
- 在Java7与Tomcat8环境下使用WebSocket实现聊天的示例
- 配置maven构建的webApp项目部署到Tomcat服务器
- Tomcat工作原理
- tomcat结合nginx使用小结
- Jenkins学习之——(3)将项目发送到tomcat
- eclipse_jee启动tomcat无法访问tomcat首页,但项目首页却可以打开