nginx作为tcp的负载均衡

news/2024/7/23 11:20:58 标签: nginx, 负载均衡

背景: 

之前总以为nginx只能当静态资源web容器和web的负载均衡,现在才知道原来也可以当tcp的负载均衡。现在我们项目测试服就是一个nginx对应了2个测试服的负载均衡。配置如下:

[root@localhost conf]# cat nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    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;

    server {
        listen       80;
        server_name  localhost;

        #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;
    #    }
    #}

}

stream {
    // 2个tcp负载均衡
    upstream gateway {
        server 10.x.x.206:10001 ;
        server 10.x.x.207:10001 ;
    }
    server {
        # 监听到1W端口
        listen 10000;
#        proxy_connect_timeout 2s;
#        proxy_timeout 30s;
        proxy_pass gateway;
    }
}


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

相关文章

MACBOOK PRO M2 MAX 安装Stable Diffusion及文生图实例

以前偶尔会使用Midjourney生成一些图片,现在使用的头像就是当时花钱在Midjourney上生成的。前段时间从某鱼上拍了一台性价比还不错的macbook,想着不如自己部署Stable Diffusion(以下简称SD)尝试一下。 网上有很多教程&#xff0c…

Kotlin 中的数据类

1 data class 在一个规范的系统架构中,数据类通常占据着非常重要的角色。 在 Java 中,定义一个数据类,通常需要为其中的每一个属性定义 get/set 方法。如果要支持对象值的比较,甚至还要重写 hashCode、equals 等方法&#xff0c…

什么是自动化测试?什么情况下使用?

什么是自动化测试? 自动化测试是指把以人为驱动的测试行为转化为机器执行的过程。实际上自动化测试往往通过一些测试工具或框架,编写自动化测试脚本,来模拟手工测试过程。比如说,在项目迭代过程中,持续的回归测试是一项非常枯燥…

rust学习(手动写一个线程池)

哈哈&#xff0c;主要是为了练习一下rust的语法&#xff0c;不喜勿喷。 一.Executor申明 struct AExecutor<T> {results:Arc<Mutex<HashMap<u32,T>>>, //1functions:Arc<Mutex<Vec<ATask<T>>>> //2 } 1.results&#xff1a…

【vue2基础教程】vue指令

文章目录 前言一、内容渲染指令1.1 v-text1.2 v-html1.3 v-show1.4 v-if1.5 v-else 与 v-else-if 二、事件绑定指令三、属性绑定指令总结 前言 Vue.js 是一款流行的 JavaScript 框架&#xff0c;广泛应用于构建交互性强、响应速度快的现代 Web 应用程序。Vue 指令是 Vue.js 中…

scrapy分布式爬虫的部署,调度,与管理(scrapy + scrapy-redis + scrapyd + gerapy)

使用到的框架及软件包介绍 Github Gerapy 提供主机管理,爬虫项目管理,爬虫任务管理的web管理后台。Github Scrapy-redis 提供中心化的任务队列,任务指纹队列,供分布式爬虫共享爬取任务队列。Github Scrapyd 提供通过api方式单机部署爬虫的功能,爬虫状态查询等。Github Scr…

突破编程_C++_设计模式(桥接模式)

1 桥接模式的基本概念 桥接模式&#xff08;Bridge Pattern&#xff09;是一种结构型设计模式&#xff0c;它的基本概念是将抽象部分与它的实现部分分离&#xff0c;使它们都可以独立地变化。在桥接模式中&#xff0c;抽象部分和实现部分被放在两个不同的类层次中&#xff0c;…

流浪猫流浪狗领养源码

流浪猫流浪狗领养源码 适合做猫狗宠物类的发信息发布。当然其他信息发布也是可以的。刚刚开发出炉的&#xff01; 源码截图&#xff1a; 免费下载地址&#xff1a;https://download.csdn.net/download/u012241616/88935678