IPFS Server Log remote access to Gateway

Is there any way to check all the remote access IP addresses and their timestamps to access my IPFS gateway? Thanks.

We have some in-memory logging for debugging don’t keep an explicit access log. I’d recommend using an nginx reverse proxy. We actually use one for our own gateways (for https and caching).

Thanks for your message.

Hi Steve,
How do I write the rules for the nginx to find the root location of IPFS gateway and api interface. I don’t know their root locations since they have been embedded into the blocks. Is there anyway to share a template for the nginx rules? Thank you for your help.

The gateway and API urls should be the ones you’ve specified in your configs. Take a look at the output of ipfs config show.

As for the rules, need to setup a reverse proxy:

For example, the following will proxy everything under the /ipfs prefix:

location /ipfs/ {
    proxy_pass http://127.0.0.1:8080/ipfs/;
}

(you can also just proxy the root (/)).

1 Like

Thank you for your help. It solved my problems. You are wonderful!

Kevin Liao

Hi Steve,
My IPFS server has only 4TB disk space, it is used by people around world to share their church faith based video files. They can post their favor video files by themselves through their web browser and send the IPFS link to their friends or relatives around world. Right now I allow them to upload their files through IPFS API(port 5001) by using js-ipfs-api upload-file-via-browser (https://github.com/ipfs/js-ipfs-api/tree/master/examples/upload-file-via-browser). It works well, however all the files they uploaded stay in the blocks forever. Is there anyway to upload files to the IPFS block and just let the files stay in the system temporarily( 1/2 days) and they will be deleted through IPFS garbage collection(gc) process. Please let me know your comments. Thank you again for your help.

Kevin

Unfortunately, we don’t have a way of saying “delete everything older than X”. The only thing you can do is remove everything that hasn’t been pinned (with GC).

However, if that’s good enough for you, you can “upload” files by using the refs API endpoint. This will force your gateway to enumerate all the blocks in the file and temporarily cache them. The endpoint is https://YOUR_GATEWAY/api/v0/refs/YOUR_HASH?recursive=true.

This one is only references the IPFS content from other node(s) not adding the new file(s) into IPFS directly from web browser.

Ah, sorry. I sometimes forget that not everyone is running an IPFS node…

We also have a writable gateway: Writeable HTTP Gateways

Hi Steve,
Thank you for your message. Actually I have a IPFS node. It is running on Ubuntu 18.04 Desktop version. I installed the nginx during past weekend, it can forward all the gateway and api requests to the local host(127.0.0.1). For example, you may visit following url http://ipshare.info/ipfs/QmaDNYb4Su6BDrwXH5c8YiDt9CzDEnaCb6N4Q3ZQdDxbLm and see how it works, the nginx works pretty well. In my API, it seems all the commands are still exposed to the outside. I only want to let /api/v0/add command/request can go through the nginx reverse proxy server and block other commands. I try to use following location rule on the nginx configuration file, to let only IPFS add commands go through the nginx reverse proxy server.

location /api/v0/add/ {
proxy_pass http://127.0.0.1:8686/api/v0/add/;
}

However the above rule blocks all the IPFS commands, including add command itself.

The rule showing below is working pretty well, however it exposes all the IPFS commands to the outside world.

location /api/v0/ {
proxy_pass http://127.0.0.1:8686/api/v0/;
}

I am not sure what is wrong with this rule???
location /api/v0/add/ {
proxy_pass http://127.0.0.1:8686/api/v0/add/;
}

Any comments from you will be highly appreciated. Thank you for your help.

Hi Steve,
Could you please give me a little bit explanations about how to use the following script.js in my application? What is index.html look like? Do I need to create it and put it in my http server root directory? Thanks for your help.

“use strict”;
function Template(text) {
let title = text.split("\n", 2)[0];
return `

${title} ${text} Save Changes to New URL `; } ; function Save() { let textarea = document.getElementById("Editor"); if (!textarea) return; // update current page HTML let newHtml = Template(textarea.value); // save changes to ipfs fetch("index.html", { method: "DELETE", redirect: "manual" }).then(deleteResponse => { // probably a bug in the gateway, // but PUT doesn't return the hash we'd expect if the file exists, so we first get a tree without it let clearedHash = deleteResponse.headers.get("ipfs-hash"); if (clearedHash) { return fetch(`/ipfs/${clearedHash}/index.html`, { method: "PUT", body: newHtml, redirect: "manual" }); } else { throw "A writeable gateway is required to save changes."; } }).then(putResponse => { let newHash = putResponse.headers.get("ipfs-hash"); // redirect location.href = `/ipfs/${newHash}/index.html`; }).catch(error => { console.log(error); alert(error); }); } ; let SaveButton = document.getElementById("Save"); SaveButton.onclick = Save;

Maybe the trailing slash; I’m sorry, I’m not that familiar with nginx? However, I recommend using the writable gateway if possible.

Could you please give me a little bit explanations about how to use the following script.js in my application? What is index.html look like? Do I need to create it and put it in my http server root directory? Thanks for your help.

I’m not entirely sure what you’re trying to do. If you’re just trying to serve static files, any answers I give will be less useful than an existing tutorial (e.g., https://medium.com/@jgefroh/a-guide-to-using-nginx-for-static-websites-d96a9d034940).

Hi Steve,
The writable gateway is working, see following curl command to post data to the gateway:

donovan@ipfs-dlchains:~$ curl -v -X POST --data ‘Hello Kevin Liao’ http://ipshare.info/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/KevinLiao.txt
Note: Unnecessary use of -X or --request, POST is already inferred.

  • Trying 75.187.208.111…
  • TCP_NODELAY set
  • Connected to ipshare.info (75.187.208.111) port 80 (#0)

POST /ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn/KevinLiao.txt HTTP/1.1
Host: ipshare.info
User-Agent: curl/7.58.0
Accept: /
Content-Length: 16
Content-Type: application/x-www-form-urlencoded

  • upload completely sent off: 16 out of 16 bytes
    < HTTP/1.1 201 Created
    < Server: nginx/1.14.0 (Ubuntu)
    < Date: Fri, 22 Jun 2018 02:22:24 GMT
    < Content-Length: 0
    < Connection: keep-alive
    < Access-Control-Allow-Headers: X-Requested-With
    < Access-Control-Allow-Headers: Range
    < Access-Control-Allow-Methods: GET
    < Access-Control-Allow-Origin: *
    < Ipfs-Hash: QmSPrDsNshu1tbzofuGYzB6oo7ALVnrogDii67urfHJiHR
    < Location: /ipfs/QmSPrDsNshu1tbzofuGYzB6oo7ALVnrogDii67urfHJiHR
    <
  • Connection #0 to host ipshare.info left intact
    donovan@ipfs-dlchains:~$

If you visit following url, you can find the data on the IPFS system.
http://ipshare.info/ipfs/QmSPrDsNshu1tbzofuGYzB6oo7ALVnrogDii67urfHJiHR

The data I just posted on IPFS is not pinned, so it will be deleted after GC. Is this right? Thanks for your help again!