Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The complete guide to hosting a public IPFS gateway

Hosting a public IPFS gateway

This guide assumes that you've used ssh before. If not, then you must read How to Set Up SSH Keys.

I'm also going to assume you've used ipfs before. If not, then take some time to discover IPFS with IPFS Desktop, IPFS Companion and go-ipfs!

Get a host

A public IPFS gateway can be hosted at home or on the cloud.

If you want to host at home, be aware that it will costs electricity and bandwidth. You can host it on an upside-down laptop running Ubuntu Server or even on a Raspberry Pi.

If you want to host it on the cloud, I recommend Digital Ocean since I've had good personal experiences with it, but really, any host can do. Digital Ocean's 5$ tier is enough to get you started!

DigitalOcean Referral Badge

Get a domain name

If you want a subdomain gateway, you'll need to use one that's compatible with Let's Encrypt's wildcard plugins. Or at least use one that allows you to change its name server to Digital Ocean, which is compatible.

Personally, I used Google Domains, but it's a bit expensive. Plus, it's not compatible with Let's Encrypt wildcards, so I had to move over the management of my domain to Digital Ocean. There are free alternatives like freenom if you're not looking for a fancy name.

Setup the server

Alright, so you've got a machine capable of running Linux and a domain name that you can use with certbot. Now we need to put IPFS and a web server on this thing.

Personally, I prefer to compile Go and IPFS, but you don't have to. It can give some performance gains by better using the CPU it's being compiled on and using more up-to-date versions of Go can offer better performance and security. Since this guide focuses on commodity hardware (or 5$ cloud), any performance we can get is beneficial.

Create an IPFS user

For better security, let's isolate the IPFS process into its own user account.

adduser ipfs

Once the user is created, you can switch to that account just as easily.

su ipfs

Next, we'll compile Go and IPFS on that user's account and setup a systemd service for IPFS.

Compiling Go

This might be a problem if you're using that 5$ Digital Ocean node since compiling Go requires 1.5 GiB RAM. You can fix this by adding 1 GiB of swap, but don't keep it on all the time. Refer to this guide if you need help setting up swap.

Warning: Although swap is generally recommended for systems using traditional spinning hard drives, placing swap on SSDs can cause issues with hardware degradation over time. Due to this, we do not recommend enabling swap on any other provider that uses SSD storage.

Get a somewhat recent Go toolchain easily accesible via a package manager. It doesn't need to be the latest version since it'll only be used to compile that latest version. I personally put drop-in applications in ~/Applications and add them to .profile. The full guide on how to compile Go is here, but here's the gist of it.

apt install git gcc
snap install go --classic
mkdir -p ~/Applications
git clone ~/Applications/go
cd ~/Applications/go/src
git checkout go1.18

Make sure to replace go1.18 with the latest Go version.

Edit your ~/.profile to access this new Go installation.

# Go

After it's edited, source ~/.profile and go version should output something like go version go1.18 linux/amd64.

Compiling IPFS

With Go compiled, it's time to tackle IPFS. The instructions are here, but here's the gist of it. I'm enabling GOTAGS=openssl in order to squeeze more performance out of it.

apt install make pkg-config libssl-dev libcrypto++-dev
mkdir -p ~/Applications
git clone ~/Applications/ipfs
cd ~/Applications/ipfs
go get
GOTAGS=openssl make install

Adding a service

IPFS offers a great deal of systemd service templates here, but I'm using a much more basic one.

Description=InterPlanetary File System (IPFS) daemon

ExecStart=/home/ipfs/go/bin/ipfs daemon --enable-gc=true --migrate=true
ExecStop=/home/ipfs/go/bin/ipfs shutdown


This service is suitable for a user account while IPFS' templates are more suitable for system-wide installations.

Now it's time to enable this service!

ipfs init --profile=lowpower,server --empty-repo
systemctl --user enable ipfs
systemctl --user start ipfs
systemctl --user status ipfs
loginctl enable-linger $USER

If you don't enable-linger, then the systemd service will close when you'll end your session. Try it a few times just to make sure it's still enabled even if you logout.

Using the domain name

To link your domain to your web server, you'll need to manage the domain and add a few records. Let's say that my domain name is I want to reuse it for other things, but I want and to be linked to the IPFS node. This lets me use other subdomains for other activities.

Here's a bunch of records I needed to setup.

Type Hostname Value
A *
A *
AAAA * 2001:db8:cad:d0::e89:2001
AAAA * 2001:db8:cad:d0::e89:2001
AAAA 2001:db8:cad:d0::e89:2001
AAAA 2001:db8:cad:d0::e89:2001
CAA 0 issue ""
CAA 0 issue ""

If I had used in its entirety for the purpose of the IPFS gateway, I wouldn't have to specify half of these. It's up to you if you want to use the whole domain on that machine or not.

The CAA records is to request that only Let's Encrypt create HTTPS certificates for this domain. It's inherited by subdomains, so technically just making one for would've been enough.


So now redirects to a valid computer with a valid IPFS gateway on it. It's time to make it a bit prettier, otherwise it'll have to be used with ugly paths such as You can return to the root user to perform these changes.

apt install nginx

If you look at /etc/nginx/sites-available/default, you'll notice this bit of config:

# Virtual Host configuration for
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#server {
#	listen 80;
#	listen [::]:80;
#	server_name;
#	root /var/www/;
#	index index.html;
#	location / {
#		try_files $uri $uri/ =404;
#	}

Aaaaand let's do that! Copy that snippet to something like /etc/nginx/sites-available/ipfs and let's make our configs there.

server {

	location /ipfs {
		proxy_set_header Host;

	location /ipns {
		proxy_set_header Host;

server {
	server_name * *;

	location / {
		proxy_set_header Host $host;

This config allows you to use /var/www/html/ to put some static HTML files in case someone ends up on your node's root. It's actually important to separate the normal and the wildcard server blocks because of the different proxy_set_header configuration. It'll be important in a few steps, when we'll enable the subdomain gateway settings on the IPFS node. The IPFS node will only issue a redirect if the host matches the part without ipfs. and ipns., so that's why we're re-writing it in the top server block.


There's no secret here, you have to go to and follow the steps there. Make sure to select wildcard instead of default and follow the step. Here's a sneak peek though:

snap install certbot --classic
snap install certbot-dns-digitalocean
certbot --dns-digitalocean --dns-digitalocean-credentials ~/.secrets/certbot/digitalocean.ini \
  --installer nginx \
  -d -d \
  -d * -d *

Congrats, you're on HTTPS! Now let's go for HTTP2. HTTP2 enables querying multiple files at the same time, which is always useful.

You can find a configuration generator at It'll conflict with certbot in a few places, though. Some settings are handled by certbot in /etc/letsencrypt/options-ssl-nginx.conf and some are handled in /etc/nginx/sites-available/ipfs. Just be careful to not break anything when you're doing changes :)

To use HTTP2, the important lines are listen 443 ssl http2; listen [::]:443 ssl http2;, the rest is related to how clients and the Nginx server communicate with HTTPS.

Subdomain gateway

Back to the ipfs user. To enable the subdomain gateway feature, you'll need to edit Gateway.PublicGateways."" in ~/.ipfs/config

  "Gateway": {
    "PublicGateways": {
      "": {
        "UseSubdomains": true,
        "Paths": [

Since the hostname is, it'll never match since this gateway is configured to use in order to liberate the root domain for other activities. This is why the Host header needs to be rewritten in Nginx a few steps above.

While we're here, you can enable add proxy_set_header X-Forwarded-Proto "https"; in Nginx to make sure the redirection happens on HTTPS.


If you want people to be able to connect to your gateway via ipfs swarm connect /dnsaddr/, then you need to add some TXT records. You can type ipfs id to get the list of addresses associated with your node.

Type Hostname Value
TXT "dnsaddr=/ip4/"
TXT "dnsaddr=/ip4/"

Once these records are added, you should be able to use ipfs swarm connect /dnsaddr/ and ipfs swarm connect /dnsaddr/, which will both do the exact same thing.


As u/CorvusRidiculissimus pointed out, people will abuse your gateway. Luckily, IPFS has a blocklist of IPFS hashes already that you can use. It probably needs to be updated to support subdomain gateways, though.

cd /etc/nginx/snippets

Once downloaded, you just have to add this bit to your server block.

include snippets/denylist.conf;

And there you have it! It should be mostly configured. The part with the subdomain gateway and the dnsaddr really fucked with me until I managed to make them work. Also Google Domain and certbot didn't work together but I didn't know so I kept trying. Sigh.

Anyway, subdomain gateways are kinda a pain in the ass to setup. Have fun.

Copy link

Hi I am Manish
I would like to deploy an ipfs public gateway at home machine.
Please help me with it.
I can pay you for helping me to deploy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment