简体   繁体   中英

How to redirect tcp to port 9300 for elasticsearch server in nginx?

I can redirect the rest communication to the elasticsearch server with this simple nginx configuration:

http {

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   30;
types_hash_max_size 2048;
client_max_body_size 50M;

include             /etc/nginx/mime.types;
default_type        application/octet-stream;

include /etc/nginx/conf.d/*.conf;
index   index.html index.htm;

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  localhost;
    root         /usr/share/nginx/html;

    include /etc/nginx/default.d/*.conf;

    location / {
        proxy_pass http://localhost:9200;
        proxy_set_header Host $host;
    }
}
}

If I try the to redirect to port 9300 for the client transport protocol it is not working, the client is not able to connect to the elasticsearch server. What is the correct nginx configuration to redirect tcp to port 9300?

Note if it's new development you should use the rest client, not the deprecated transport client. https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-transport.html#_tcp_transport You will probably need to set set transport.publish_port and transport.publish_host...

If reverse proxy is just TCP proxy it should work, here is the doc from nginx on tcp proxy : https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM