英文:
kafka nginx 400 157 "-" "-"
问题
我想创建一个用于Kafka的Docker Compose文件,但是Nginx出现了400错误。
如何修改我的代码?
192.168.0.8是Broker服务器
192.168.0.16是Producer服务器和Nginx服务器
- 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
- 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服务器。
- 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
- 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
- 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
- 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论