1, 测试环境
a) 3台centos虚拟机IP分别为190,191,192
b) 安装软件三台安装nginx。
在http://nginx.org/下载需要版本
tar -zxvf pcre-8.21.tar.gz
cd pcre-8.21
./configure
make
make install
启动nigix并进行访问。
/usr/local/nginx/sbin/nginx -c /root/nginx-1.6.2/conf/nginx.conf
后面参数为配置文件地址。因为下载地址为root下故在/root/nginx-1.6.2/conf/nginx.conf。
修改vi /usr/local/nginx/html/index.html,用于区分不同的nginx的访问
<title>Welcome to nginx!本地IP地址 web page</title>
将对应IP进行测试访问。
2, 使用191作为主服务器,所有访问均通过191负载到190,191或192上。
修改191上/root/nginx-1.6.2/conf/nginx.conf配置文件
加入
upstream a.com {
least_conn; //使用负载的策略
server 192.168.0.190:80;
server 192.168.0.192:80;
}
修改:
location / {
root html;
index index.html index.htm;
proxy_pass http://a.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;
}
注意上面红色部分.
重启
重新加载配置
kill -HUP $nginx_pid
或者
/usr/nginx/sbin/nginx -s reload
但在加载前最好检查一下配置文件:
nginx -t -c /usr/nginx/conf/nginx.conf
或者
/usr/nginx/sbin/nginx -t
访问 http://192.168.0.191进行访问测试。 页面跳转190或192.
3, 对自己进行负载
问题:使用了三台nginx却只有两台可以进行访问,那么还有一台也像作为访问对象怎么办?
在191上加入多端口监听。多一个server配置。
server {
listen 8080;
server_name 192.168.0.200;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#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;
# }
#}
并upstram配置中:
upstream a.com {
least_conn;
server 192.168.0.191:8080;
server 192.168.0.190:80;
server 192.168.0.192:80;
}
测试访问。即可。
分享到:
相关推荐
ngnix+tomcat实现负载均衡的配置
NULL 博文链接:https://zxf-noimp.iteye.com/blog/1931626
freeswitch支持UDP、TCP、WS(websocket)、WSS方式进行注册,而反向代理是指通过nginx配置,通过WSS的方式连接WS,这样使得freeswitch连接对外是加密的;当然freeswitch本身是支持WSS的, 用ngnix一般除了反向代理,...
Ngnix+php5完整环境配置加文件,以及实现负载平衡的配置文件
负载均衡 利器 nginx 部分配置已配置好 修改下即可使用
redHat安装ngnix,以及负载均衡配置-附件资源
NGINX +TOMCAT在windows下的负载均衡的集群配置
ngnix讲解的需求以及各种配置示例图
1,tomcat8的配置: 1.1修改tomcat8.x/conf/context.xml的配置如下: <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file ...
学习的nginx配置信息,包括反向代理,负载均衡,和ip过滤。
uniGUI 的 HyperServer(负载均衡)简单使用说明 uniGUI 的 HyperServer 是一个节点管理的应用程序,主要实现了节点的自动管理,也就是负载均衡的功能。HyperServer 程序是 uniGUI 1.5 版本后新增加的功能,可以...
Nginx各种配置(包括负载均衡、静态代理、动静分离)
ngnix实战取代apache的高性能web服务器。一本不错的介绍Ngnix HTTP服务器的书籍,内容涵盖Ngnix的优点,安装,配置,优化,与PHP、JSP、ASP.NET、Perl的协同,负载均衡配置、模块开发、缓存等。
今天学习了ngnix负载均衡,搭了个环境测试了下,并记录了搭建过程。nginx负载均衡配置过程,利用两台redhat 5.5服务器搭建了nginx的负载均衡。有图,安装过程。
真正实现一键自动化部署,Nginx+Tomcat+Redis 实现负载均衡集群服务搭建,所有文件自动生成,包括自动生成配置文件参数、解决依赖问题、Session共享同步问题等等,直接把 Web 应用的 war 包,放进Tomcat的 webapps ...
第6章 Nginx HTTP负载均衡和反向代理的配置与优化 第7章 Nginx的Rewrite规则与实例 第8章 Nginx模块开发 第9章 Nginx的Web缓存服务与新浪网的开源NCACHE模块 第10章 Nginx在国内知名网站中的应用案例 第11章 Nginx的...
该Docker映像提供了一个预配置的Nginx实例,该实例被配置为反向代理。 此外,此映像包含实用程序,可让您以最少的停机时间快速重新配置反向代理后端。 该映像使用phusion-passenger和runit作为多进程Docker容器运行...