basho / riak-erlang-client

The Riak client for Erlang.
Apache License 2.0
311 stars 188 forks source link

Connecting to Riak KV cluster through Nginx Reverse Proxy #385

Closed SserwangaV closed 3 years ago

SserwangaV commented 4 years ago

I'm trying to connect to the Riak cluster through reverse proxy to leverage load balancing and abstract the applications from the cluster configurations. I succeed to open up a socket connection, but the connection is not persistent, that is, I get a response {error,disconnected} immediately. This is unlike the case when I connect to a Riak node directly where the connections stay as long as they are not closed or interrupted externally.

Here below is the snippet of the configuration

upstream riak_cluster_servers { least_conn; keepalive 32; server riak1.example.com:8087; server riak2.example.com:8087; server riak3.example.com:8087; server riak4.example.com:8087; server riak5.example.com:8087; }

The server block is setup as below

server { listen 0.0.0.0:80; listen [::]:80; server_name riak.example.com; location / { proxy_pass http://riak_cluster_servers; proxy_http_version 1.1; proxy_set_header Connection ""; } }

What could be causing this issue?

aboroska commented 4 years ago

@dotsiadia Did you set the tuple {keepalive, true} in riakc_pb_socket options? Setting keepalive as atom means false unintuitively. See: #383

SserwangaV commented 4 years ago

@aboroska I set {keepalive, true} like this, {ok, Pid} = riakc_pb_socket:start('riak.example.com', 80, [{keepalive, true}]).. I immediately run riakc_pb_socket:ping(Pid). and get {error,disconnected}

SserwangaV commented 4 years ago

It seems Nginx can only proxy HTTP (Layer 7) protocols not TCP (Layer 4) protocols that are used by the protocol buffer. Thus, Nginx is likely to be useful when connecting to Riak using REST methods.

martinsumner commented 4 years ago

Not sure if you still have this as a problem. The repo issues aren't tracked by many people, but you can try the slack channel instead at postriak.slack.com

I know that using NGiNX as a proxy to the HTTP should work fine, as there are many users connecting this way.

SserwangaV commented 4 years ago

@martinsumner send me an in from postriak.slack.com.