I try to setup HTTP authentication for my private geth node on my server using nginx as reverse proxy. I followed this instruction: https://ethereum.stackexchange.com/questions/30357/restricted-access-authentication-for-a-remote-geth-node
I tested my setup with curl
and it is working fine so far:
curl
-X POST
--header "Content-Type: application/json"
--data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}'
https://<user>:<pw>@<domain>
Result: {"jsonrpc":"2.0","id":1,"result":[<addresses>]}
Opening the domain in my browser works fine as well, I see the authentication prompt and after entering the credentials there is no error.
My node looks like this:
docker run -d ethereum/client-go:stable
--datadir "/root"
--port 30001
--nat "any"
--nodiscover
--rpc
--rpcaddr "0.0.0.0"
--rpcport 8545
--rpcapi "eth,net,web3,rpc"
--rpccorsdomain "*"
--rpcvhosts "*"
Problem
Unfortunately I can't connect to my node with web3
:
web3 = new Web3(new Web3.providers.HttpProvider("https://<user>:<pw>@<domain>"));
console.log(web3.eth.coinbase);
Result in browser:
Error: CONNECTION ERROR: Couldn't connect to node https://<user>:<pw>@<domain>.
// this error I just get in Chrome, not in Firefox. But if I ask with `curl -I` I can see `Access-Control-Allow-Origin` is set.
web3.min.js:1 Access to XMLHttpRequest at 'https://<user>:<pw>@<domain>' from origin 'https://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.