Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | 云栖社区 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Github | Search | About

34.4. HTTP 网关

默认 IPFS 监听 127.0.0.1 使用下面命令启动IPFS守护进程,然后使用 nginx 代理 127.0.0.1

		
[ipfs@netkiller ~]$ ipfs daemon
Initializing daemon...
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/172.31.180.30/tcp/4001
Swarm listening on /p2p-circuit/ipfs/QmZakCF5czhP53KPvMi8XQcYtVrQohw5N71Xce4eC1rWz3
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/172.31.180.30/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready
		
		

34.4.1. 访问文件

			
[root@netkiller ~]# hash=$(cat /etc/centos-release | ipfs add -q)
[root@netkiller ~]# curl "http://127.0.0.1:8080/ipfs/$hash"
CentOS Linux release 7.4.1708 (Core)
			
			

34.4.2. 配置代理服务器

Nginx 配置

			
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

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

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
			
			
			
[root@netkiller ~]# hash=$(cat /etc/centos-release | ipfs add -q)
[root@netkiller ~]# curl "http://localhost/ipfs/$hash"
CentOS Linux release 7.4.1708 (Core)
			
			

使用浏览器访问文件

http://localhost/ipfs/QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn

ipfs.io 节点
			
[root@netkiller ~]# hash=$(cat /etc/centos-release | ipfs add -q)
[root@netkiller ~]# curl "https://ipfs.io/ipfs/$hash"
CentOS Linux release 7.4.1708 (Core)
			
			

34.4.4. 监听地址

或者修改配置文件直接暴漏地址出去

			
[ipfs@netkiller ~]$ export EDITOR=/usr/bin/vim
[ipfs@netkiller ~]$ ipfs config edit

"API": "/ip4/127.0.0.1/tcp/5001",
"Gateway": "/ip4/127.0.0.1/tcp/8080"

"API": "/ip4/你的IP地址/tcp/5001",
"Gateway": "/ip4/你的IP地址/tcp/8080"