kafka nginx 400 157 “-” “-“

huangapple go评论57阅读模式
英文:

kafka nginx 400 157 "-" "-"

问题

我想创建一个用于Kafka的Docker Compose文件,但是Nginx出现了400错误。

在此输入图片描述

如何修改我的代码?

192.168.0.8是Broker服务器
192.168.0.16是Producer服务器和Nginx服务器

  1. docker-compose.yml
version: '2'
services:
  nginx:
    image: nginx:1.21.5-alpine
    ports:
      - 4000:4000
      - 443:443
    volumes:
      - ./proxy/nginx.conf:/etc/nginx/nginx.conf
    container_name: nginx-server
  1. nginx.conf
user nginx;
events {
 worker_connections 1000;
}

http {
 upstream all {
    ip_hash;
    server 192.168.0.8:9092;
    server 192.168.0.8:9093;
    server 192.168.0.8:9094;
}
 server {
    server_name  192.168.0.8;
    listen 4000;
  
    location / {
       proxy_pass http://all/;
       proxy_set_header Host $host;
    }
 }
}

upstream all 包含3个Broker服务器。

  1. kafkajs配置
const { Kafka } = require('kafkajs');
const { Partitioners } = require('kafkajs');

const kafkaClient = new Kafka({
  clientId: 'icas-client',
  brokers: ['192.168.0.8:4000'],
});

const producer = kafkaClient.producer({ createPartitioner: Partitioners.LegacyPartitioner });

const consumer = kafkaClient.consumer({ groupId: 'icas' });
module.exports.kafkaClient = kafkaClient;
module.exports.producer = producer;
module.exports.consumer = consumer;
英文:

I wana create docker-compose file nginx proxy for kafka
but nginx had problem 400

enter image description here
how to modify my code

192.168.0.8 is broker server
1922.168.0.16 is producer server and nginx server

  1. docker-compose.yml
version: '2'
services:
  nginx:
    image: nginx:1.21.5-alpine
    ports:
      - 4000:4000
      - 443:443
    volumes:
      - ./proxy/nginx.conf:/etc/nginx/nginx.conf
    container_name: nginx-server
  1. nginx.conf
user nginx;
events {
 worker_connections 1000;
}

http {

 upstream all {
  
    ip_hash;
  server 192.168.0.8:9092;
  server 192.168.0.8:9093;
  server 192.168.0.8:9094;
}
 server {
  
  server_name  192.168.0.8;

  listen 4000;
  
  location / {
     proxy_pass http://all/;
      proxy_set_header Host $host;
  }
 }
 
}

upstream all is 3 broker server

  1. kafkajs config
const { Kafka } = require('kafkajs');
const { Partitioners } = require('kafkajs');

const kafkaClient = new Kafka({
  clientId: 'icas-client',
  brokers: ['192.168.0.8:4000'],
});

const producer = kafkaClient.producer({ createPartitioner: Partitioners.LegacyPartitioner });

const consumer = kafkaClient.consumer({ groupId: 'icas' });
module.exports.kafkaClient = kafkaClient;
module.exports.producer = producer;
module.exports.consumer = consumer;

答案1

得分: 0

Kafka使用TCP而不是HTTP,所以这不会起作用。

Kafka客户端已经本地进行负载均衡,因此没有理由引入反向代理。

英文:

Kafka uses TCP, not HTTP, so this will not work

Kafka clients already load balance, natively, so there's no reason to introduce a reverse proxy

huangapple
  • 本文由 发表于 2023年7月10日 13:11:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76650798.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定