This post is mainly to help reader to deploy an IPFS service with nginx proxy which provides basic authorizations.
A quick start is the following steps.
Some basic requirements:
- Docker should already be installed on your computer.
- Basic Linux terminal skills.
Create files
Create folder
$ mkdir ipfs $ cd ipfs
Create
docker-compose.yaml
version: '3' services: ipfs: container_name: ipfs image: ipfs/kubo:latest volumes: - ./data/:/data/ipfs/ ports: - '8080:8080' restart: always nginx: container_name: nginx image: nginx:latest ports: - '5001:5001' volumes: - './default.conf:/etc/nginx/conf.d/default.conf:ro' - './htpasswd:/htpasswd:ro' restart: always
Create
htpasswd
ljiang:$apr1$nShUpvO7$hizri44cnQwto/zQ0y3Ka0
Create
default.conf
server { listen 5001; server_name _; client_max_body_size 2048000m; location / { proxy_pass http://ipfs:5001; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; auth_basic "Administrator’s Area"; auth_basic_user_file /htpasswd; } }
Init IPFS Data
Make data folder
$ mkdir -p ./data/
Init data
$ IPFS_PATH="$(pwd)/data/" ipfs init
Set IPFS config
Set Addresses
$ IPFS_PATH="$(pwd)/data/" ipfs config --json Addresses.API '"/ip4/0.0.0.0/tcp/5001"' $ IPFS_PATH="$(pwd)/data/" ipfs config --json Addresses.Gateway '"/ip4/0.0.0.0/tcp/8080"'
Set API
$ IPFS_PATH="$(pwd)/data/" ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]' $ IPFS_PATH="$(pwd)/data/" ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "PUT", "POST"]'
Start IPFS
$ docker-compose up -d