Hi,
I’m new to nginx. I’m trying to configure nginx with elasticsearch on windows OS. I’m trying to redirect the http request automatically to secondary node(localhost:9201) if primary node(localhost:9200) is down using nginx .Can anyone please help me ? Thanks in advance.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
@sinduja
The best way to set things up would be to separate things out instead of combining them all in to one single file.
For example,
nginx.conf
at the location below.The above file would have something such as (for a more complete configuration):
Now above, you’ll see:
That’s saying that NGINX should include all configuration files in the
./sites-available
directory, which is where you’d place your website specific configuration (your server blocks) – i.e.Now, for a full proxy setup, create a file in
/etc/nginx/sites-available/
named something likeInside that file, paste in:
In the
upstream
block, you need to use IP’s or Hostnames, as I’ve showcased above. You can’t uselocalhost
since all your servers are not actually served by the same droplet. You should also use a name for theupstream
other thanlocalhost
since that’s a reserved name in most all configurations.Once you have everything configured with your IP’s / Ports (simply replace my IP’s in the
upstream
block with your own), you’d need to restart NGINX.@jtittle
nginx config file:
events { worker_connections 1024; }
http { upstream localhost {
server { listen 80; server_name localhost:9200; location / { proxy_pass http://localhost; } } }
I have 3 ES nodes. Its supposed to redirect automatically when the primary node is down. Am i doing anything wrong. any advise would be helpful. Thanks in advance.
@sinduja
If you want to direct requests based on whether one node is up or down, then you’d need to setup a third node and let it function as the primary entry point for requests. In doing so, you’d be setting up a load balanced solution.
This load balancer node accepts incoming requests and directs them to servers that are listed in the
upstream
block (as noted in the guide). In the event one of them is down, requests are automatically routed to the next node in the list.DigitalOcean actually has a basic guide on how to set this up, which I’d recommend taking a look at first.
https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-load-balancing