How to connect js-ipfs node on browser to go-ipfs node on remote server?

Hello, I encountered a problem and look forward to getting help:
I have 2 ipfs nodes, one is the js-ipfs daemon running on the browser, the other is the go-ipfs running on my remote server,
I used the code to start the js-ipfs daemon on the browser, it only runs on the browser, without installing any software or plug-ins,
I tried to connect the js-ipfs node on the browser to the go-ipfs node on my server, but it failed.

My js-ipfs starts like this:
const node = await Ipfs.create({ repo: userName });

The browser can be connected to the following nodes on the public network:










But I can’t connect to my own server go-ipfs node, and can only use the form with the domain name above, not the form with IP,
For example:’/ip4/’, this form is invalid.

I need help, I look forward to you helping me

Hello @enochzhao

Browser nodes do not support TCP transport, as the browser environment does not support it. In this scenario you described, you need to add listen addresses for you go-libp2p node using websockets and use the websocket transport to connect to it.

If you have a look into the DNS multiaddrs you provided, you can see that they are using websockets because of the /wss part.

Let me know if you could make this work

Hello, thank you very much for your reply,

I made the following configuration in config and used nginx for proxy forwarding, but no connection was successful,
I am a newbie, can you tell me the error in the configuration or operation process

ipfs config:

“Addresses”: {
“API”: “/ip4/”,
“Announce”: [],
“Gateway”: “/ip4/”,
“NoAnnounce”: [],
“Swarm”: [

nginx config:

server {
listen 443;
server_name domain-name;
ssl on;

    ssl_certificate   /etc/nginx/cert/ipfs/a.pem;
    ssl_certificate_key  /etc/nginx/cert/ipfs/a.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    location /websocket {

   		proxy_pass http://ip.ip.ip.ip:4001;
	proxy_set_header Host $host;
	proxy_http_version 1.1;
 	proxy_set_header Upgrade $http_upgrade;    
 		proxy_set_header Connection "Upgrade";
	proxy_set_header X-Real-IP $remote_addr;
        		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        		proxy_connect_timeout 60;
       		proxy_read_timeout 600;
       		proxy_send_timeout 600; 

listen 80;
server_name domain-name;
rewrite ^(.*) https://{server_name}$1 permanent;

If I understood correctly your flow, you want to establish a connection from a js-ipfs node to a go-ipfs node that you already know its multiaddr. My answer will have this scenario in account.

For this scenario, I recommend that you use the default configuration ( as you do not need to listen for new connections in the browser node. It will be the starter party for establishing a connection.

As I mentioned, we cannot use TCP within the browser. Your configuration seem all TCP oriented and go-ipfs listens on TCP by default. This way, what I think you need is to add a websocket listen address in the go node (Some information:

Considering a different scenario, where you actually also want your node to listen for connections from other parties. If this is your end goal, you should at the js-ipfs repo browser examples, and also to this thread on SSL certificates for webrtc-transport

Hope that this helps you

Thank you, great, I used the method in this link, the browser connects to the go-ipfs node on the remote server Succeeded,
As you said, I implemented this function: the remote server go-ipfs node can listen to the connection of other nodes as well as the connection of the browser node. Thank you for your help! ! !

1 Like