Home | 简体中文 | 繁体中文 | 杂文 | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | Github | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

29.3. HTTP 网关

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

29.3.1. 查看网关地址

			
[ipfs@netkiller ~]$ ipfs config Addresses.Gateway
/ip4/127.0.0.1/tcp/8080			
			
			

29.3.2. 添加测试文件

			
[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)
			
			

29.3.3. 配置代理服务器

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)
			
			

29.3.5. 监听地址

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

			
[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"