Cannot access from outside localhost
Closed this issue · 10 comments
Using docker, if I try to check a transaction from other machine, nothing is displayed.
Example:
http://192.168.0.123:8080/tx/0x5d9f0075e01b91bb15dc20f98e0c73b059ff37d9d73663238ca01fa696da36e7
but I can access perfectly from localhost:
http://localhost:8080/tx/0x5d9f0075e01b91bb15dc20f98e0c73b059ff37d9d73663238ca01fa696da36e7
The docker console says:
geth-explorer | 192.168.0.100 - - [10/Mar/2020:13:46:46 +0000] "GET /js/app.bundle.js.map HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0" "-"
and the webconsole of my web-browser is stuck in:
Data sources loaded. TransportConsole.ts:36:21
NOTE:
- 192.168.0.123: is the machine executing the docker with the port 8080 visible for connecting to the docker
- 192.168.0.100: is the machine where I am accessing
Are there any errors printed to the console? Your console should look something like this:
Initializing Alethio CMS @ 1.0.0-beta.##...
Loading plugin plugin://aleth.io/eth-common?v=#.#.#...
Loading plugin plugin://aleth.io/eth-lite?v=#.#.#...
Plugins loaded.
Loading data sources...
Data sources loaded.
You can also take a peek at the network tab and see if there are any failed requests.
After a while a message appears:
Initializing Alethio CMS @ 1.0.0-beta.7... TransportConsole.ts:36:21
Loading plugin plugin://aleth.io/eth-common?v=2.4.0... TransportConsole.ts:36:21
Loading plugin plugin://aleth.io/3box?v=1.1.0... TransportConsole.ts:36:21
Loading plugin plugin://aleth.io/eth-lite?v=2.2.0... TransportConsole.ts:36:21
Plugins loaded. TransportConsole.ts:36:21
Loading data sources... TransportConsole.ts:36:21
Data sources loaded. TransportConsole.ts:36:21
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://172.25.0.110:8545/. (Reason: CORS request did not succeed).
NOTE: 172.25.0.110:8545 is the local docker node which serves the RPC calls
I have disabled all my blockers as suggested in:
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSDidNotSucceed
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://172.25.0.110:8545/. (Reason: CORS request did not succeed).
This means you need to add/update the CORS configuration in your local node server so that it allows http://192.168.0.123:8080
as origin (See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin).
If you're not using HTTP authentication, adding Access-Control-Allow-Origin: *
to the response should suffice. Otherwise it has to be set explicitly to http://192.168.0.123:8080
.
If you have no direct control over that server you could create a proxy that adds the headers and point the client application to it instead.
I have change the default.conf of the nginx server to allow CORS, but still the same problem.
In the machine executing the docker, even using the global address (192.168.0.123) works well
It is weird, but the header "access-control-allow-origin" does not appear.
This is the /etc/nginx/conf.d/default.conf of the node running the ethereum-lite-explorer:
server {
# Define the server name, IP address, and/or port of the server
listen 80;
# Define the specified charset to the "Content-Type" response header field
charset utf-8;
root /usr/share/nginx/html;
index index.html index.html;
# static content in production
location / {
try_files $uri $uri/ /index.html;
# maximum file size on file uploads
client_max_body_size 100K;
# accept requests from everywhere
add_header 'Access-Control-Allow-Origin' '*';
}
}
And this is how I run the geth node:
geth --bootnodes "enode://${bootnodeId}@${bootnodeIp}:30301" --networkid "6660001" --verbosity=4 --rpc --rpcaddr "0.0.0.0" --rpcapi "eth,web3,net,admin,debug,personal" --rpccorsdomain "*" --syncmode="full" --nousb --allow-insecure-unlock
But still the access-control-allow-origin does not appear (only in OPTIONS method)
It has to be set at the geth node, not the lite explorer nginx. But it looks like you're already doing this by calling geth
with --rpccorsdomain "*"
. Are you using http or https for the nodeUrl? If it's https, then "*"
will not work. It has to be an explicit domain (e.g.http://182.168.0.123:8080
). Otherwise it should be fine.
EDIT: is the geth node directly exposed or do you have a reverse proxy in front of it?
NOTE: 172.25.0.110:8545 is the local docker node which serves the RPC calls
You need to use the public IP or lan (192.168.x.x) IP instead.
Thank you, that solves my problem!
I have changed:
APP_NODE_URL=http://172.25.0.110:8545
for
APP_NODE_URL=http://192.168.0.123:8545