Setup Your Own IPFS Gateway
Create VPS on cloud
- Create Instance on DO/AWS
- Configure a security group with the following options:
Custom TCP: 8080
Custom TCP: 4001–4002
- SSH into your EC2 instance
Install “go-ipfs”
- Select a Linux binary from https://dist.ipfs.io/go-ipfs/
e.g. https://dist.ipfs.io/go-ipfs/v0.14.0/go-ipfs_v0.14.0_linux-amd64.tar.gz
- Unzip:
tar -xvzf go-ipfs_v0.14.0_linux-amd64.tar.gz
- Navigate to the correct directory:
cd go-ipfs
- Run the install script:
sudo bash install.sh
- Check that IPFS was installed correctly by running:
ipfs --version
Initialize the IPFS repository
- Create a directory:
mkdir /home/ubuntu/data/ipfs
- Add the path to your Bash profile:
echo 'export IPFS_PATH=/home/ubuntu/data/ipfs >> ~/.profile'
- Reload your bash profile:
source ~/.profile
- Initialize the IPFS repository:
ipfs init --profile server
- Open the Gateway on port 8080:
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
Set up an IPFS daemon
- Create a systemd service:
sudo vim /lib/systemd/system/ipfs.service
- Add the following contents to the file:
[Unit]
Description=ipfs daemon
[Service]
ExecStart=/usr/local/bin/ipfs daemon --enable-gc
Restart=always
User=ubuntu
Group=ubuntu
Environment=”IPFS_PATH=/home/ubuntu/data/ipfs”
[Install]
WantedBy=multi-user.target
- Save the file
- Restart the daemon:
sudo systemctl daemon-reload
- Enable the service:
sudo systemctl enable ipfs.service
- Start the service:
sudo systemctl start ipfs
- Check the status:
sudo systemctl status ipfs
Make your IPFS Writable
- Edit IPFS configuration:
sudo vim /home/ubuntu/data/ipfs/config
- Set json key .Gateway.Writable = true
{
......
"Gateway": {
"APICommands": [],
"HTTPHeaders": {
"Access-Control-Allow-Headers": [
"X-Requested-With",
"Range",
"User-Agent"
],
"Access-Control-Allow-Methods": [
"GET",
"POST",
"PUT"
],
"Access-Control-Allow-Origin": [
"*"
]
},
"NoDNSLink": false,
"NoFetch": false,
"PathPrefixes": [],
"PublicGateways": null,
"RootRedirect": "",
"Writable": true
},
......
}
- Restart ipfs:
sudo systemctl restart ipfs
Support Form-Data upload
- Nginx proxy
cat /etc/nginx/conf.d/ipfs_gw.conf
upstream gateway {
server 127.0.0.1:8080;
}
upstream api {
server 127.0.0.1:5001;
}
server {
server_name _;
root /var/www/html;
access_log /var/log/nginx/access.log;
listen 80 default_server;
listen [::]:80 default_server;
#include conf.d/gateway/denylist.conf;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'X-Requested-With, Range, Content-Range, X-Chunked-Output, X-Stream-Output' always;
add_header 'Access-Control-Expose-Headers' 'Content-Range, X-Chunked-Output, X-Stream-Output' always;
client_max_body_size 100M;
proxy_pass_header Server;
proxy_read_timeout 1800s;
location / {
proxy_set_header Host $host;
proxy_set_header X-Ipfs-Gateway-Prefix "";
proxy_pass http://gateway;
}
location /api/v0/ {
proxy_set_header Host $host;
proxy_set_header X-Ipfs-Gateway-Prefix "";
proxy_pass http://api;
}
}