nginx apache负载均衡测试
apache配置
(监听内网ip和端口)
Listen 10.163.170.8:8001
Listen 10.163.170.8:8002
Listen 10.163.170.8:8003 <VirtualHost *:8001>
DocumentRoot /website/111.com
ServerName localhost:8001
DirectoryIndex index.html index.php
ErrorLog logs/111.com-error_log
CustomLog logs/111.com-access_log common
</VirtualHost> <VirtualHost *:8002>
DocumentRoot /website/222.com
ServerName localhost:8002
DirectoryIndex index.html index.php
ErrorLog logs/222.com-error_log
CustomLog logs/222.com-access_log common
</VirtualHost> <VirtualHost *:8003>
DocumentRoot /website/333.com
ServerName localhost:8003
DirectoryIndex index.html index.php
ErrorLog logs/333.com-error_log
CustomLog logs/333.com-access_log common
</VirtualHost>
nginx配置
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;
# 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;
upstream webservers {
server 10.163.170.8:8001 weight=1;
server 10.163.170.8:8002 weight=2;
server 10.163.170.8:8003 weight=3;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://webservers;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
php测试
(nginx_upstream_test.php)
<?php
$url = 'http://114.215.107.17/';
$count = 100; $webservers = array();
for($i=1; $i<=$count; $i++){
echo($i."\n");
$data = test($url);
$webservers[$data]++;
}
var_dump($webservers); function test($url){
$data = file_get_contents($url);
return trim($data);
}
?>
测试结果1
array(3) {
[]=>
int(34)
[]=>
int(49)
[]=>
int(17)
}
测试结果2
array(3) {
[]=>
int(51)
[]=>
int(33)
[]=>
int(16)
}
nginx apache负载均衡测试的更多相关文章
- nginx作为负载均衡服务器——测试
i. 需求 nginx作为负载均衡服务器,用户请求先到达nginx,再由nginx根据负载配置将请求转发至 tomcat服务器. nginx负载均衡服务器:192.168.101.3 tomcat1服 ...
- Nginx网络架构实战学习笔记(三):nginx gzip压缩提升网站速度、expires缓存提升网站负载、反向代理实现nginx+apache动静分离、nginx实现负载均衡
文章目录 nginx gzip压缩提升网站速度 expires缓存提升网站负载 反向代理实现nginx+apache动静分离 nginx实现负载均衡 nginx gzip压缩提升网站速度 网页内容的压 ...
- nginx+tomcat负载均衡
最近练习nginx+tomcat负载均衡.根据一些资料整理了大体思路,最终实现了1个nginx+2个tomcat负载均衡. 安装JDK 1>进入安装目录,给所有用户添加可执行的权限 #chmod ...
- nginx做负载均衡配置文件
nginx做负载均衡是在反向代理的基础上做的,代码如下: ## Basic reverse proxy server ## ## Apache backend for www.baidu.com ## ...
- linux+nginx+tomcat负载均衡,实现session同步
linux+nginx+tomcat负载均衡,实现session同步 花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞 ...
- 利用nginx实现负载均衡和动静分离
1.Nginx介绍 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器 . Nginx 是由 ...
- Nginx+Keepalived负载均衡高可用
Nginx+Keepalived负载均衡高可用方案: Nginx 使用平台:unix.linux.windows. 功能: A.www web服务 http 80 b.负载均衡(方向代理proxy) ...
- Nginx实现负载均衡功能
一.什么是Nginx? Nginx是一款轻量级的Web 服务器.反向代理服务器.电子邮件(IMAP/POP3)代理服务器. 二.Nginx的优点: 高并发连接:官方测试Nginx能够支撑5万并发连接, ...
- 若依项目利用nginx实现负载均衡及保持会话
记录一下若依项目利用nginx实现负载均衡及保持会话的步骤. 此次作为试验性的测试,为了方便在本地window的环境上实现. 具体步骤: 1.安装两个tomcat8,可以下载一个后,另一个复制即可,下 ...
随机推荐
- Redis应用场景
Redis开创了一种新的数据存储思路,使用Redis,我们不用在面对功能单调的数据库时,把精力放在如何把大象放进冰箱这样的问题上,而是利用Redis灵活多变的数据结构和数据操作,为不同的大象构建不同的 ...
- SpringMVC 中获取所有的路由配置。
ApplicationContext context = TMSContextLookup.getApplicationContext(); String[] controllerList = con ...
- 设置ajax 同步执行
Ajax请求默认的都是异步的如果想同步 async设置为false就可以(默认是true) var html = $.ajax({ url: "some.php", async ...
- 保持const和non-const函数代码的一致
在用C++进行面向对象编程的时候,有时需要在一个类里包含两个代码相似的函数,而它们之间的唯一区别是,一个为const类型,一个是non-const类型. 此时如果将相同的代码写在两个函数中,则严重违反 ...
- 1.date 命令
转自:http://www.cnblogs.com/peida/archive/2012/12/13/2815687.html 在linux环境中,不管是编程还是其他维护,时间是必不可少的,也经常会用 ...
- 使用BeanUtils工具类操作Java bean
1.类的属性: 1).在Java EE中,类的属性通过setter和getter定义:类中的setter(getter)方法去除set(get)后剩余的部分就是类的属性 2).而之前叫的类的属性,即成 ...
- ORACLE 10G 闪回建议
Flashback Tips The following tips and restrictions apply to using flashback features. Flashback Tips ...
- sencha touch 入门系列 (二)sencha touch 开发准备
这是本人第一次写博客教程,没什么经验,文笔也不是很好,写这教程一方面为了巩固自己这段时间的学习成果,一方面帮助大家解决问题,欢迎大家多提建议,指出问题.接下来我们就开始我们的sencha touch开 ...
- HTML实体字符转化为HTML标签
html_entity_decode方法 参数 描述 string 必需.规定要解码的字符串. flags 可选.规定如何处理引号以及使用哪种文档类型. 可用的引号类型: ENT_COMPAT - 默 ...
- 多个 git ssh key 配置 Ubuntu os
1.生成ssh key: ssh-keygen -t rsa -C “email@sss.com” 此时,在~/.ssh/文件夹下会有两个文件, id_rsa 和 id_rsa.pub.分别保存ssh ...