• 使用nginx实现反向代理


    1    使用nginx实现反向代理

    Nginx只做请求的转发,后台有多个http服务器提供服务,nginx的功能就是把请求转发给后面的服务器,决定把请求转发给谁。

    1.1   安装tomcat

    在一个虚拟机上创建两个tomcat实例,模拟多个服务器。

    1.2   需求

    通过访问不同的域名访问运行在不同端口的tomcat

    8080.itheima.com  访问运行8080端口的tomcat

    8081.itheima.com  访问运行8081端口的tomcat

    1.3   域名需要配置host(Windows)文件:

    1.4   Nginx的配置

     1 upstream tomcatserver1 {
     2     server 192.168.83.133:8081;
     3     }
     4     upstream tomcatserver2 {
     5     server 192.168.83.133:8082;
     6     }
     7    server {
     8         listen       80;
     9         server_name  8081.ccc.com;
    10 
    11         #charset koi8-r;
    12 
    13         #access_log  logs/host.access.log  main;
    14 
    15         location / {
    16             proxy_pass   http://tomcatserver1;
    17             index  index.html index.htm;
    18         }
    19 
    20         
    21     }
    22     server {
    23         listen       80;
    24         server_name  8082.ccc.com;
    25 
    26         #charset koi8-r;
    27 
    28         #access_log  logs/host.access.log  main;
    29 
    30         location / {
    31             proxy_pass   http://tomcatserver2;
    32             index  index.html index.htm;
    33         }
    34 
    35         
    36     }

    浏览器访问:

    如果在同一个域名下有多台服务器提供服务,此时需要nginx负载均衡。

  • 相关阅读:
    hive原理和调优
    python+Eclipse+pydev环境搭建
    使用eclipse上Tomcat插件配置域名、端口号、启动时间详解
    java工具包一:日期处理
    枚举传参,枚举使用详解
    java面试题大全
    八:Lombok 安装、入门
    Java8一:Lambda表达式教程
    七:程序员必读书单
    二:熟悉 TCP/IP 协议
  • 原文地址:https://www.cnblogs.com/116970u/p/10481125.html
Copyright © 2020-2023  润新知