1

I have been resolving issues related to IPFS access and it seems the design is that 127.0.0.1 is used for local updates with an API interface to a app. I have 5001 access issues and I have checked already IPFS CORS.

Here is the error -

POST http://jenbil.com:5001/api/v0/cat?arg=QmU5KhkgvweYgE3Gsr8A19uFQrq7mszx7dubcoo89cTmAV&stream-channels=true net::ERR_CONNECTION_REFUSED

I have this config -

{
  "API": {
    "HTTPHeaders": {
      "Access-Control-Allow-Credentials": [
        "true"
      ],
      "Access-Control-Allow-Methods": [
        "PUT",
        "POST",
        "GET"
      ],
      "Access-Control-Allow-Origin": [
        "*"
      ]
    }
  },
  "Addresses": {
    "API": "/ip4/127.0.0.1/tcp/5001",
    "Gateway": "/ip4/127.0.0.1/tcp/8180",
    "Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip6/::/tcp/4001"
    ]
  },
  "Bootstrap": [
    "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",


    "/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx"
  ],
   "Datastore": {
     "BloomFilterSize": 0,
     "GCPeriod": "1h",
     "HashOnRead": false,
     "NoSync": false,
     "Params": null,
     "Path": "/root/.ipfs/datastore",
     "StorageGCWatermark": 90,
     "StorageMax": "10GB",
     "Type": "leveldb"
   },
   "Discovery": {
     "MDNS": {
       "Enabled": true,
       "Interval": 10
     }
   },
   "Experimental": {
     "FilestoreEnabled": false,
     "ShardingEnabled": false
   },
   "Gateway": {
     "HTTPHeaders": {
       "Access-Control-Allow-Headers": [
         "X-Requested-With"
       ],
       "Access-Control-Allow-Methods": [
         "GET"
       ],
       "Access-Control-Allow-Origin": [
         "*"
       ]
     },
     "PathPrefixes": [],
"RootRedirect": "",
     "Writable": false
   },
   "Identity": {
     "PeerID": "QmNwbtyFuEBDoB2BQGNe144jJXGJPJ9QrcwzNDMuqGYiZ9"
   },
   "Ipns": {
     "RecordLifetime": "",
     "RepublishPeriod": "",
     "ResolveCacheSize": 128
   },
   "Mounts": {
     "FuseAllowOther": false,
     "IPFS": "/ipfs",
     "IPNS": "/ipns"
   },
   "Reprovider": {
     "Interval": "12h"
   },
   "SupernodeRouting": {
     "Servers": null
   },
   "Swarm": {
     "AddrFilters": null,
     "DisableBandwidthMetrics": false,
     "DisableNatPortMap": false
   },
   "Tour": {
     "Last": ""
   }

And the config file for Nginx

server {
    listen 80 default_server;
listen 8080;
listen 5001;
listen 8180;
    listen [::]:80 default_server ipv6only=on;

#   root /usr/share/nginx/html/ipfs/src;
#
root /usr/share/nginx/html;
#root /var/www/html;
index index.html index.htm index.nginx-debian.html;
#   index App.js index.html index.htm;
#listen   443 ssl;
server_name jenbil.com;
#server_name _;
#ssl    on;
#ssl_certificate    /home/keys/jenbil.com.chained.crt;
#ssl_certificate_key    /home/keys/jenbil.key;

    # Make site accessible from http://localhost/
###jenbil   server_name localhost;

    location / {
2
  • I mean 5001 of course. May 17, 2017 at 14:49
  • I'm not sure if this is the problem, but it might be an issue with port collisions. Try using something unused, like :15001 and :18080 for ports in the IPFS config (bound to localhost only), and use 5001 and 8080/8180 in nginx redirecting them to the 1xxxx port counterparts.
    – Mateon1
    May 18, 2017 at 16:11

2 Answers 2

1

What are you trying to do with this request to IPFS?

cat is a read operation, so you should use the HTTP GET action, not POST, with /api/v0/cat.

2
  • Have you any code example? I cannot even see where GET is specified. May 19, 2017 at 14:39
  • Browsers, curl and most HTTP client libraries use HTTP GET by default. There are many examples of how to use the IPFS HTTP API at ipfs.io/docs/api They all use curl, which you can treat as a stand-in for whichever client library you choose. The specific documentation for the cat command is at ipfs.io/docs/api/#apiv0cat May 20, 2017 at 15:17
0

You need to set the IPFS host to 0.0.0.0

ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/9001

You may also need to set CORS:

ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'

Restart IPFS daemon.

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.