Sony Arouje

a programmer's log

Posts Tagged ‘Windows

nginx and Elasticsearch in Windows

leave a comment »

The system I was working might need more than one Elasticsearch node configured as Master or Load balancer. I wanted to come up with a logic to connect to a different node in case of node failure. That means I have to write logic to check the status of a node before sending any index or search request. If the status failed, take the next node from the configured list and check the status. This is a viable approach but more concerned about the performance impact of my logic.

I started searching for a system that can open up a proxy IP and group the elasticsearch instance’s under that ip. This way the client will be aware of this proxy ip and not the individual ip and port details of Elasticsearch nodes. Also any node failures will be handled by the proxy system. After some exploration I decided to try nginx, it has built in load balancing with very simple configuration. I downloaded the mainline version of nginx for Windows and installed it.

To modify the nginx configuration go to conf\nginx.conf and open the configuration file in any text editor and add your configuration. See my configuration below.

worker_processes  1;
events {
worker_connections  1024;

http {

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

upstream elasticcluster{
server weight=1 fail_timeout=1;
server weight=1 fail_timeout=1;

sendfile        on;
keepalive_timeout  65;
server {
listen       8080;

location / {
proxy_pass  http://elasticcluster;
proxy_connect_timeout 1;

error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;


In the upstream I group all my Elasticsearch nodes under elasticcluster. In the server’s proxy_pass I specify the upstream name, eg. http://elasticcluster. That’s it, now I can access my elastic search node via and nginx will route the traffic to any one of my Elasticsearch node in round robin manner. As you can see nginx ip and port is configured via listen and server_name settings.

Now all my search or index request goes to nginx ip and nginx will route the traffic to any of the Elasticsearch node running in my dev machine. I test failover by stopping one of my Elasticsearch node and nginx routed the traffic to the other live nodes.

Issue with localhost

Initially I configured nginx and Elasticsearch to use different ports of localhost. This causes some huge delay in nginx to route traffic to Elasticsearch nodes. I found this post from nginx forum and realized that the issue is with localhost. So I configured all my Elasticsearch instance to use the ip address instead of localhost. Also configured nginx.conf and specify as server_name, you can also give the IP address instead of

Leave your comments below if you find it helpful or have any questions. Thanks for reading.

Happy coding…

Written by Sony Arouje

March 3, 2014 at 6:39 pm

Create Facebook Hash Key for Android apps

with 41 comments

Currently doing a small Facebook client for Android. There are several steps we need to do to get the integration working properly. Here I just give a brief of how to create Hash key to update in Facebook. I did a lot of research to get things working, so thought of writing a post that give the details in one place.

Steps to create Hash Key.

  1. Download openssl from Openssl for Windows . I downloaded the Win32 version
  2. Unzip and copy all the files in the bin folder including openssl.exe
  3. Goto to the folder where you installed JDK for me it’s C:\Program Files\Java\jdk1.6.0_21\bin
  4. Paste all the files you copied from Openssl’s bin folder to the Jdk folder.

Now it’s time to run the command to generate the HashKey. You can find more details of Facebook sdk here

keytool -exportcert -alias androiddebugkey  -keystore [Key_store_path] | openssl sha1 -binary | openssl enc -a -e


Above command needs the path to your debug keystore. You can find the Keystore path using Eclipse. Goto Window->Preference->Android->Build will open up a window as shown below.


You can find the Default debug keystore. Copy the path and update in our command, now the command will be like

keytool -exportcert -alias androiddebugkey  -keystore C:\Users\sarouje\.android\debug.keystore | openssl sha1 -binary | openssl enc -a -e

Fire a command prompt and paste the command and run it. Tool will generate a key for you.

Edit: I was not successful in generating right Key Hash using command prompt or cygWin. My search leads to this post explains how to generate right key for the app. Author also provided the Eclipse project contains the source.

Update Hash Key in Facebook

Goto to your Facebook app page and click Edit settings of your app. Click on the Mobile Native section, page will expand and show the section as shown below


Update the HashKey in the Android Key Hash Textbox and click save changes. We are done, go ahead and run your app and it will work fine. No more Invalid key exception


Edit (Jun-24-2014): Nezzar Waleed notified me about one easy solution he found out in stackoverflow, please check it out as well.

Written by Sony Arouje

September 18, 2011 at 3:42 am

%d bloggers like this: