Skip to content

Instantly share code, notes, and snippets.

@D1360-64RC14
Last active July 16, 2022 04:38
Show Gist options
  • Save D1360-64RC14/692bd34bd6d0aca13e6a54576c183c0e to your computer and use it in GitHub Desktop.
Save D1360-64RC14/692bd34bd6d0aca13e6a54576c183c0e to your computer and use it in GitHub Desktop.
My Docker NGINX configuration for local IPFS gateway.

This is my Docker-NGINX-IPFS environment.

Docker Images

Endpoints

URL Description Redirect
http://<server-ip>/ipfs Open gateway's WebUI http://<gateway-ip>:5001/webui
http://<server-ip>/ipfs/<CID> Get content from IPFS network http://<gateway-ip>:8080/ipfs/<CID>
http://<server-ip>/ipns/<NID> Resolve IPNS address http://<gateway-ip>:8080/ipns/<NID>
http://<server-ip>/ "404 Not Found" Nginx's page

Using outside Docker

You can use the ipfs.conf outside a docker container, but just remember to change the proxy_pass address to yours.

services:
nginx:
container_name: NGINX
image: nginx:alpine
ports:
- 80:80
networks:
- nginx-lan
volumes:
- type: volume
source: nginx-data
target: /etc/nginx
restart: unless-stopped
ipfs:
container_name: IPFS
image: ipfs/go-ipfs
ports:
- 4001:4001
- 5001:5001
- 8080:8080
networks:
- nginx-lan
volumes:
- type: volume
source: ipfs-data
target: /data/ipfs
restart: unless-stopped
volumes:
nginx-data:
ipfs-data:
networks:
nginx-lan:
driver: bridge
# Place this file at /etc/nginx/conf.d/ipfs.conf
server {
listen 80;
server_name localhost;
proxy_set_header Host $host;
proxy_set_header User-Agent $http_user_agent;
allow all;
# Disable Buffering
proxy_buffering off; # Disable buffer from proxy to client
proxy_request_buffering off; # Disable buffer from client to proxy
# Disable Proxy Cache
proxy_no_cache 1;
# No timeout errors
keepalive_timeout 3600s;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
client_body_timeout 3600s;
location /api {
proxy_pass http://ipfs:5001; # <-------- Can't have the trailling slash
}
# http://localhost/ipfs redirects to webui
location = /ipfs {
proxy_pass http://ipfs:5001/webui/; # <- Should have the trailling slash
}
location ~* /(ipfs|ipns) {
proxy_pass http://ipfs:8080; # <-------- Can't have the trailling slash
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment