2

in my geth.service file I have..

Description=Ethereum Go Client
[Service]
ExecStart=/usr/bin/geth --cache=1000 --datadir=/mnt/eth-blockchain --keystore=/mnt/eth-blockchain --rpc --rpcport=8882 --rpccorsdomain=* --
rpcapi=web3,db,net,eth
Restart=always
RestartSec=30
Type=simple
User=root
Group=root
[Install]

And in the nginx conf file /etc/nginx/conf.d/eth.domain.com.conf I have...

limit_req_zone $binary_remote_addr zone=one:10m rate=30r/m;
limit_conn_zone $binary_remote_addr zone=addr:10m;

server {
    listen 80;
    client_body_timeout 5s;
    client_header_timeout 5s;
    server_name eth.domain.com;

    location / {
        limit_req zone=one;
        limit_conn addr 10;        
        proxy_pass http://localhost:8882;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204;
    }
}

I run the below code in the browser

    web.eth.getBalance('0xa1fe5d3ca40da27705847361351c34a3e77d187a', 'latest', function(error, result){
        if(!error)
            console.log(result)
        else
            console.error(error);
    })

And the response is..

web3-hook.html:68 Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (web3.min.js:1)
    at XMLHttpRequest.n.onreadystatechange (web3.min.js:2)

If I change the host to a different RPC server I don't get the error message, so I know it's a server issue. Both geth and nginx look right to me, what am I missing?

I have also tried starting it from the console with

admin.startRPC("127.0.0.1", 8882, "*", "web3,db,net,eth")

and then I can curl it with

curl -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' localhost:8882

and I get the response

{"jsonrpc":"2.0","id":67,"result":"Geth/@binky/v1.6.0-stable-facc47cb/linux-amd64/go1.8.1"}
  • Use curl to do a raw JSON-RPC request and inspect the response manually to see the actual underlying error – Mikko Ohtamaa Apr 15 '17 at 15:40
  • Mikko do you have an example curl command I can use? Also do I run it on the server or locally? – Bill Apr 15 '17 at 15:52
  • There should be example curl commands in Ethereum JSON-RPC API manual. – Mikko Ohtamaa Apr 15 '17 at 15:53
  • I tried curl -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' eth.domain.com and i get no response – Bill Apr 15 '17 at 15:55
  • the example in Ethereum JSON-RPC API manual is. curl -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' but it returns curl: no URL specified! – Bill Apr 15 '17 at 15:57
1

all of this is not necessary

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;
    return 204;

I then had to remove

--rpc --rpcport=8882 --rpccorsdomain=* --rpcapi=web3,db,net,eth

then start the console and do

admin.startRPC("127.0.0.1", 8882, "*", "web3,db,net,eth")

at this point, it was all working. I added back

 --rpc --rpcport=8882 --rpccorsdomain=* --rpcapi=web3,db,net,eth

rebooted and all is still good!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.