nginx轮询负载均衡演示demo
1.nginx /conf/nginx.conf配置文件
#user nobody;
worker_processes auto; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; pid logs/nginx.pid; events {
use epoll;
worker_connections 1024;
} http {
include 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 logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; upstream yes.oktokeep.com { server 127.0.0.1:8882;
server 127.0.0.1:8883;
server 127.0.0.1:8881;
server 127.0.0.1:8884;
} server {
listen 80;
server_name yes.oktokeep.com; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
proxy_pass http://yes.oktokeep.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }
2.修改 /etc/hosts文件
增加映射 127.0.0.1 yes.oktokeep.com
3.创建nodejs文件,模拟4个应用,文件内容一样,仅仅端口号不同
8881.js(同理创建8882.js,8883.js,8884.js文件)
var http = require("http");
http.createServer(function(request,response){
response.writeHead(200,{"Content-Type":"text/plain"});
response.write("Hello Nignx,I am warking on port 8881.\n");
response.end(); }).listen(8881); console.log("nodejs start listen 8881 port!\n");
var http = require("http");
http.createServer(function(request,response){
response.writeHead(200,{"Content-Type":"text/plain"});
response.write("Hello Nignx,I am warking on port 8882.\n");
response.end(); }).listen(8882); console.log("nodejs start listen 8882 port!\n");
var http = require("http");
http.createServer(function(request,response){
response.writeHead(200,{"Content-Type":"text/plain"});
response.write("Hello Nignx,I am warking on port 8883.\n");
response.end(); }).listen(8883); console.log("nodejs start listen 8883 port!\n");
var http = require("http");
http.createServer(function(request,response){
response.writeHead(200,{"Content-Type":"text/plain"});
response.write("Hello Nignx,I am warking on port 8884.\n");
response.end(); }).listen(8884); console.log("nodejs start listen 8884 port!\n");
4.启动nginx, node 8881.js &
5.模拟请求
上传3份nodejs文件
node /usr/workspace/nodejs/8881.js &
node /usr/workspace/nodejs/8882.js &
node /usr/workspace/nodejs/8883.js &
node /usr/workspace/nodejs/8884.js &
##使用轮询的方式来访问
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8883.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8884.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8882.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8881.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8883.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8884.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8882.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8881.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8883.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8884.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8882.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8881.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8883.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8884.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8882.
[root@VM-4-3-centos /]# curl http://yes.oktokeep.com
Hello Nignx,I am warking on port 8881.
nginx轮询负载均衡演示demo的更多相关文章
- Dubbo加权轮询负载均衡的源码和Bug,了解一下?
本文是对于Dubbo负载均衡策略之一的加权随机算法的详细分析.从2.6.4版本聊起,该版本在某些情况下存在着比较严重的性能问题.由问题入手,层层深入,了解该算法在Dubbo中的演变过程,读懂它的前世今 ...
- Nginx+Tomcat实现负载均衡小demo
一.搭建Tomcat服务 下载安装JDK和Tomcat就不说了,太简单了.由于是win7单机环境测试,启动多个Tomcat服务可以通过在server.xml配置文件中修改端口实现.准备两个Tomcat ...
- Docker + Nginx + Tomcat 实现负载均衡简单演示
Docker + Nginx + Tomcat 实现负载均衡 环境 [root@pinyoyougou-docker ~]# docker -v Docker version 1.12.6, buil ...
- Nginx 简单的负载均衡配置演示样例
近期在做开放查询应用的时候,因为数据两天特别多,两千多万条呢,用户訪问需求也比較大,所以就用nginx做了 负载均衡,以下是改动之后的相关内容. http://www.cnblogs.com/xiao ...
- 如何使用Weave以及Docker搭建Nginx反向代理/负载均衡服务器
Hi, 今天我们将会学习如何使用 Weave 和 Docker 搭建 Nginx 的反向代理/负载均衡服务器.Weave 可以创建一个虚拟网络将 Docker 容器彼此连接在一起,支持跨主机部署及自动 ...
- windows下利用nginx 做IIS负载均衡
如果网站流量变大,就想加服务器分担压力,当然就要用到负载均衡,在windows 2003有自带的网络负载均衡,但配置还是挺麻烦的虽然有轮训和iphash的效果,但效果不算好. nginx小巧,下载不到 ...
- Nginx配之负载均衡、缓存、黑名单和灰度发布
一.Nginx安装(基于CentOS 6.5) 1.yum命令安装 yum install nginx –y(若不能安装,执行命令yum install epel-release) 2. 启动.停止和 ...
- Nginx 反向代理 负载均衡 虚拟主机配置
Nginx 反向代理 负载均衡 虚拟主机配置 通过本章你将学会利用Nginx配置多台虚拟主机,清楚代理服务器的作用,区分正向代理和反向代理的区别,搭建使用Nginx反向搭理和负载均衡,了解Nginx常 ...
- Nginx/LVS/HAProxy 负载均衡软件的优缺点详解
Nginx/LVS/HAProxy 负载均衡软件的优缺点详解 Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,参考了一些资料,结合自己的一些使用经验 ...
- Nginx 反向代理 负载均衡 虚拟主机
Nginx 反向代理 负载均衡 虚拟主机配置 通过本章你将学会利用Nginx配置多台虚拟主机,清楚代理服务器的作用,区分正向代理和反向代理的区别,搭建使用Nginx反向搭理和负载均衡,了解Nginx常 ...
随机推荐
- 如何进行基于Anolis OS的企业级Java应用规模化实践?|龙蜥技术
简介:提供了7×24小时的专属钉钉或者电话支持,响应时间保证到在业务不可用情况下10分钟响应,业务一般的问题在一小时可以获得响应,主要城市可以两小时内得到到达现场的服务. 本文作者郁磊,是Java语 ...
- [FAQ] Docker查询出所有的停止容器并移除
$ docker rm `docker container ls -a --filter "status=exited" | awk '{print $1}' | sed '1,1 ...
- dotnet 6 使用 DependentHandle 关联对象生命周期
本文将告诉大家在 dotnet 6 新加入的 System.Runtime.DependentHandle 的类型的使用方法,通过 DependentHandle 可以实现将某个对象的引用生命周期和另 ...
- hbuilder打包报错:java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 7 column 15 path $.icons
一个棘手的问题,在网上找几乎没有出现这样的案例,个别也只有翻译没有解决方式,,,,,自己研究一番发现这实际上都不算是个问题 这句话翻译:这个位置应该是个对象而不是数组,解决方法: 在manifest. ...
- 一键自动化博客发布工具,用过的人都说好(oschina篇)
oschina和segmentfault一样,界面非常的清爽. 界面上除了必须的标题,内容之外,还有文章专辑和推广专区这几个选项. 一起来看看在blog-auto-publishing-tools中, ...
- Vue3.x+springboot集成pageoffice
说明:由于pageoffice浏览器是ie内核,vue3不兼容ie.所以需要把页面放在后端 一,前端项目: 1.index.html页面引用pageoffice.js <script type= ...
- Django——admin后台上传文件
from django.db import models class Mytb(models.Model): file = models.FileField(upload_to='uploads/') ...
- C#简易商城收银系统v1.1简单工厂实现(2-2)
C#简易商城收银系统v1.1简单工厂实现(2-2) 当初: C#简易商城收银系统v1.0 现在: 用之前的工厂模式对商城收银系统v1.0进行升级 可以参考之前的 C#简易商城收银系统v1.0 随笔 ...
- 领域驱动设计(Domain-Driven Design,简称DDD)【简介 个人学习笔记】
找到了第 1 篇资料:领域驱动设计详解:是什么.为什么.怎么做? - 知乎 找到了第 2 篇资料:领域驱动架构(DDD)建模中的模型到底是什么? - 知乎 找到了第 3 篇资料:一文看懂DDD 领域驱 ...
- Tkinter界面实操
常用opencv-python进行图像处理,有时需要图形用户界面,写个Demo以备不时之需. Tkinter 1. 导入库 由于 Tkinter 是内置到 python 的安装包中.只要安装好 Pyt ...