nginx实现轮询机制(nginx基础配置一)

news/2024/9/21 17:20:16 标签: nginx, idea

一、首先在 nginx的conf配置一下代理

###定义上游服务器(需要被nginx真实代理访问的服务器) 默认是轮训机制
upstream backServer{
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
server {
listen 80;
server_name upstream.boyatop.cn;
location / {
### 指定上游服务器负载均衡服务器
proxy_pass http://backServer;
index index.html index.htm;
}
}

二、在idea新建两个项目

项目一:

package com.qcby.nginx2.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class NginxTest {

    

    /**
     * 访问controller实现代理访问
     */
    @ResponseBody
    @RequestMapping("/")
    public String getBoyatop01(){
        //打印证明接口被访问
        System.out.println("接口被访问8080!!");
        return "Hello World qcbySpringBootNginx8080!!!!";
    }


}

项目二:

package com.qcby.nginx2.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class NginxTest {

    /**
     * 访问controller实现代理访问
     */
    @ResponseBody
    @RequestMapping("/")
    public String getBoyatop01(){
        //打印证明接口被访问
        System.out.println("接口被访问8081!!");
        return "Hello World qcbySpringBootNginx8081!!!!";
    }


}

三、访问监听端口进行校验

first test:

 

 second test:

 四、总结

会轮询的访问两个端口


http://www.niftyadmin.cn/n/5669148.html

相关文章

react 甘特图之旅

react-gantt GitHub 仓库: https://github.com/clayrisser/react-gantt react-gantt-chart GitHub 仓库: https://github.com/MaTeMaTuK/gantt-task-react easy-gant-beta GitHub 仓库: https://github.com/web-widgets/react-gantt-demos 上面的版本不兼容 dhtmlx-gant…

【智能大数据分析 | 实验一】MapReduce实验:单词计数

【作者主页】Francek Chen 【专栏介绍】 ⌈ ⌈ ⌈智能大数据分析 ⌋ ⌋ ⌋ 智能大数据分析是指利用先进的技术和算法对大规模数据进行深入分析和挖掘,以提取有价值的信息和洞察。它结合了大数据技术、人工智能(AI)、机器学习(ML&a…

IS-ISv6单拓扑存在的问题

文章目录 IS-ISv6单拓扑配置单拓扑存在的问题解决 IS-ISv6单拓扑 配置 R1:sy sy R1 ipv6 inter g0/0/0 ip add 12.1.1.1 24 ipv6 enable ipv add 2001:12::1 64 inter loop0 ip add 1.1.1.1 32 ipv6 enable ipv address 2002::1 128isis net 49.111111111111.00 is…

每日OJ题_牛客_WY22 Fibonacci数列(斐波那契)

目录 牛客_WY22 Fibonacci数列(斐波那契) 解析代码 牛客_WY22 Fibonacci数列(斐波那契) Fibonacci数列_牛客题霸_牛客网 解析代码 求斐波那契数列的过程中,判断⼀下:何时 n 会在两个 fib 数之间。 #in…

如何将 java.nio.ByteBuffer 转为 String

如何将 java.nio.ByteBuffer 转为 String 方法1: newString()方法结合ByteBuffer的array()方法, 忽略是否flip()过 用String的 public String(byte[] bytes, int offset, int length, Charset charset)方法 和 ByteBuffer的array()方法 长度在取 bbf.position()0?bbf.limit(…

GD32F103单片机-EXTI外部中断

GD32F103单片机-EXTI外部中断 一、EXTI及NVIC介绍二、编程实验2.1 相关库函数2.2 实验代码 一、EXTI及NVIC介绍 GD32和STM32的EXTI基本相似,具体见STM32F1单片机-外部中断GD32的EXTI包括20个相互独立的边沿检测电路请求产生中断或事件,4位优先级配置寄存…

漏洞——CVE简介

1、什么是CVE CVE (Common Vulnerabilities and Exposures)(常见漏洞与暴露)是一个标准化的命名系统,用于识别和描述公开披露的网络安全漏洞。CVE 的目的是为漏洞提供唯一的标识符,使安全专家、软件供应商和用户能够统一参考和讨…

ABAP-Swagger 一种公开 ABAP REST 服务的方法

ABAP-Swagger An approach to expose ABAP REST services 一种公开 ABAP REST 服务的方法 Usage 1: develop a class in ABAP with public methods 2: implement interface ZIF_SWAG_HANDLER, and register the public methods(example method zif_swag_handler~meta) 3: …