反向代理相比于正向代理, 比如使用搬瓦工时, 就是位于客户端的正想代理, 而反向代理则是服务器端的代理, 主要用于实现请求分发, 负载均衡等功能

正向代理推荐一个: 搬瓦工, 比较好用..

反向代理主要有2个重要的配置:

proxy_pass    C语言的代理函数

upstream

1, 直接通过proxy_pass配置nginx访问tomcat服务器

 # 虚拟主机1
server {
listen ;
server_name wenbronk.nginx-.com; #charset koi8-r; #access_log logs/host.access.log main; location / {
# 配置允许规则
allow 192.168.1.0/;
allow 192.168.0.0/;
deny all; # 配置用户访问控制
auth_basic "basicAccess";
auth_basic_user_file /usr/nginx-passwd; #root html;
#index index.html index.htm;
proxy_pass http://localhost:8080;
}
error_page /50x.html;
location = /50x.html {
root html;
} }

一定要加最后的 ; !!!!!!!

此时, 通过访问 wenbronk.nginx-01.com 就可以访问tomcat首页了

2, 实现负载均衡

使用upstream

upstream_名字 {
  server: IP:PORT weight=;
} server {
  location /{
    proxy_pass: http://名字;
  } }
 upstream weight_tomcat {
server 192.168.208.101: weight=;
server 192.168.208.102: weight=;
} # 虚拟主机1
server {
listen ;
server_name wenbronk.nginx-.com; #charset koi8-r; #access_log logs/host.access.log main; location / {
# 配置允许规则
allow 192.168.1.0/;
allow 192.168.208.0/;
deny all; # 配置用户访问控制
auth_basic off;
auth_basic_user_file /usr/nginx-passwd; #root html;
#index index.html index.htm;
proxy_pass http://weight_tomcat;
}
...
...
}

其中的 weight= 1 既可以实现轮询时的负载均衡功能

系列来自尚学堂极限班

4-nginx-反向代理到tomcat及负载均衡的更多相关文章

  1. .net core 跨平台开发 微服务架构 基于Nginx反向代理 服务集群负载均衡

    1.概述 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客 ...

  2. Nginx反向代理实现Tomcat负载均衡

    这篇短文主要介绍Tomcat的集群和用Nginx反向代理实现Tomcat负载均衡. 1.首先需要对一些知识点进行扫盲(对自己进行扫盲,囧): 集群(Cluster) 简单来说就是用N台服务器构成一个松 ...

  3. Nginx反向代理实现Tomcat+Jpress和halo

    一.利用Nginx反向代理Jpress+Tomcat 1.环境准备 服务器 IP地址 作用 系统版本 Proxy代理服务器 10.0.0.101 负载均衡Nginx Web服务器 Ubuntu2004 ...

  4. Nginx反向代理实现Tomcat多个应用80端口访问

    应用背景 一般我们在开发时,一个工程里会有多个Web应用,比如一个前台一个后台,那我们就需要配置2个Tomcat服务器,比如一个是http://localhost:8080,一个是http://loc ...

  5. nginx反向代理(proxy_pass)tomcat的过程中,session失效的问题解决

    Nginx反向代理tomcat,很是方便,但是也有些细节的问题需要注意:今天遇到了这样一个问题,tomcat中路径“host/web1”,nginx中直接“host/”代理,这时候session就无法 ...

  6. 【转】Nginx反向代理转发tomcat

    http://blog.csdn.net/mlc1218559742/article/details/53117520 最近刚接触nginx,在网上查阅了相关资料,看到最多的形容nginx的词就是反向 ...

  7. 通过Nginx TCP反向代理实现Apache Doris负载均衡

    概述 Nginx能够实现HTTP.HTTPS协议的负载均衡,也能够实现TCP协议的负载均衡.那么,问题来了,可不可以通过Nginx实现Apache Doris数据库的负载均衡呢?答案是:可以.接下来, ...

  8. Nginx反向代理到Tomcat服务器

    在实际生产中,Tomcat服务器一般不单独使用在项目中,对于静态资源的响应Nginx表现的比较好,另外由于nginx是专门用于反向代理的服务器,所以很容易实现将java的请求转发到后端交给tomcat ...

  9. linux下nginx【反向代理】配置【负载均衡】配置

    nginx 可以配置多个端口: 1.10088端口 配置反向代理,消除跨域问题. 2.10087端口 配置ip_hash模式的负载均衡,ip_hash可以绕开解决session共享的问题. nginx ...

  10. Nginx加多个tomcat实现负载均衡,动静分离

    一:Nginx+Tomcat的动静分离 所谓动静分离就是通过nginx(或apache等)来处理用户端请求的图片.html等静态的文件,tomcat(或weblogic)处理jsp.do等动态文件,从 ...

随机推荐

  1. HDU1501 Zipper(DFS) 2016-07-24 15:04 65人阅读 评论(0) 收藏

    Zipper Problem Description Given three strings, you are to determine whether the third string can be ...

  2. Informatica bulk和normal模式

    转载:http://bestxiaok.iteye.com/blog/1107612 Bulk 方式进行目标数据的Load,是Informatica提供的一种高性能的Load数据方式.它利用数据库底层 ...

  3. Ansible配置文件

    官方配置文件文档 Ansible安装完成之后默认配置文件为:/etc/asnible/ansible.cfg Ansible配置文件内容: cat ansible.cfg # config file ...

  4. git archive命令详解

    git archive可以将加了tag的某个版本打包提取出来,例如: git archive -v --format= > v0..zip --format表示打包的格式,如zip,-v表示对应 ...

  5. LeetCode135:Candy

    题目: There are N children standing in a line. Each child is assigned a rating value. You are giving c ...

  6. Alwayson 基本概念

    1. AD域服务: 存储目录数据并管理用户与域之间的通信,包括用户登录处理.身份验证和目录搜索. 2. AD林:林是域的最大组织单元,一个林可以包括一个或多个域.林中的域之间相互信任(默认). 3. ...

  7. Openlayers地图量算功能

    http://openlayers.org/en/latest/examples/measure.html?q=measure   按官网的例子来就行,新建对象时注意加上命名空间   var vect ...

  8. C#读取excel文件,并生成json

    这次介绍两种方法,第一种是安装AccessDatabaseEngine,第二种是利用Npoi读取excel 一.第一种利用AccessDatabaseEngine进行读取excel文件 1.安装Acc ...

  9. C#默认以管理员身份运行程序实现代码

    using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; names ...

  10. c# 1-2+3-4.....求和

    找规律: 下界:1 上界:n class Program { static void Main(string[] args) { ; ; i <=; i++) { ==) { sum -= i; ...