Ipfs
IPFS/Nginx 埠 2001
我一直在解決與 IPFS 訪問相關的問題,似乎設計是 127.0.0.1 用於通過應用程序的 API 介面進行本地更新。我有 5001 訪問問題,並且我已經檢查了 IPFS CORS。
這是錯誤 -
POST http://jenbil.com:5001/api/v0/cat?arg=QmU5KhkgvweYgE3Gsr8A19uFQrq7mszx7dubcoo89cTmAV&stream-channels=true net::ERR_CONNECTION_REFUSED
我有這個配置 -
{ "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": "" }
以及 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 / {
你想對 IPFS 的這個請求做什麼?
cat
是讀取操作,因此您應該使用 HTTP GET 操作,而不是 POST,與/api/v0/cat
.
您需要將 IPFS 主機設置為
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
您可能還需要設置 CORS:
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
重新啟動 IPFS 守護程序。