Ethereum Block Explorer – How to Securely Connect Geth Running on Main Server

explorersgo-ethereumjson-rpcprivate-blockchain

I am working on private Ethereum Network. I run Ethereum boot-node and Ethereum Block Explorer app ( https://github.com/etherparty/explorer (A lightweight ethereum block explorer.) ) on the main server.

Inside the main server where I run Ethereum node, at the browser I could connect into the Ethereum Block Explorer from localhost:8000:

enter image description here

But from an external node on the browser, when I try to connect from main server's ip address < ip-address >:8000 I have faced with the following error message. The main reason of this error message was "web3 is not connected"

enter image description here

var eth_node_url = 'http://localhost:8545'; // TODO: remote URL
web3.setProvider(new web3.providers.HttpProvider(eth_node_url));

if(!web3.isConnected()) {
    $('#connectwarning').modal({keyboard:false,backdrop:'static'}) //enters here
    $('#connectwarning').modal('show') //enters here
}

On the external node, if I run geth app on the background that is already connected to the private Ethereum network, it solves the problem.

[Q] On the external node without running the geth app on the background, is it possible for Ethereum Block Explorer to connect into the geth app that is already running on the main server? If yes, is there a secure approach as running geth with --rpcaddr="localhost" --rpccorsdomain="*" on the main server?

Thank you for your valuable time and help.

Note:

=> The way I run the Ethereum Node:

geth --port 3000 --networkid 23422 --nodiscover --datadir="/home/MyEthereumEbloc" 
--rpc --rpcaddr="localhost" --rpccorsdomain="*" --maxpeers=6 --ipcapi 
"admin,eth,web3" --autodag

=> In order to install Ethereum Block Explorer, I have followed the installation guide on https://github.com/etherparty/explorer.

[~$] git clone https://github.com/etherparty/explorer 
[~$] cd explorer
[~/explorer$] npm start

> EthereumExplorer@0.1.0 prestart /home/netlab/explorer
> npm install


> EthereumExplorer@0.1.0 postinstall /home/netlab/explorer
> bower install


> EthereumExplorer@0.1.0 start /home/netlab/explorer
> http-server ./app -a 79.123.177.145 -p 8000 -c-1

Starting up http-server, serving ./app on port: 8000

=> Inside package.json file that is located under explorer folder: app started as follows:

"start": "http-server ./app -a localhost -p 8000 -c-1"

Please know that when I have changed localhost to node'a ip-address it didn't help:

"start": "http-server ./app -a <ip-address> -p 8000 -c-1"

Best Answer

!!Please note that this solution only works if external node and the main server is in the same Network Domain!!

Insecure approach:

The problem was: how I start my RPC.

Run geth on the main server as follows:

> admin.startRPC("0.0.0.0", 8545, "*")
true

or

--rpc --rpcport 8545 --rpcaddr 0.0.0.0 --rpccorsdomain "*" --rpcapi "eth,web3"

Update explorer/app/app.js as follows:

    //var eth_node_url = 'http://localhost:8545'; //commented out. 
    var eth_node_url = 'http://<ip-address of the main server>:8545';         
    web3.setProvider(new web3.providers.HttpProvider(eth_node_url));
Related Topic