From 4734f08e7b1f60025f54bbfb3a6baea128bdfbbf Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Sat, 3 Oct 2015 14:45:59 +0200 Subject: [PATCH] gateway: add /refs/* Rewrites requests for /refs/a/b/c to c.b.a.refs.ipfs.io. Also replaces conditionals with location directives, which are evaluated more efficiently. License: MIT Signed-off-by: Lars Gierth --- .../templates/nginx_ipfs_gateway.conf.j2 | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/solarnet/roles/ipfs_gateway/templates/nginx_ipfs_gateway.conf.j2 b/solarnet/roles/ipfs_gateway/templates/nginx_ipfs_gateway.conf.j2 index d1d1cbc..600e6c7 100644 --- a/solarnet/roles/ipfs_gateway/templates/nginx_ipfs_gateway.conf.j2 +++ b/solarnet/roles/ipfs_gateway/templates/nginx_ipfs_gateway.conf.j2 @@ -76,15 +76,22 @@ server { resolver 8.8.8.8 8.8.4.4; - set $hosturi $host$uri; - set $proxyhost ""; - if ($hosturi !~ "^(h\.)?ipfs\.io/(ipfs|ipns|api)(/|$)") { - set $proxyhost $host; + location /refs/ { + rewrite "^/refs/([^/]+)/([^/]+)/([^/]+)$" "/" break; + proxy_set_header Host $3.$2.$1.refs.ipfs.io; + proxy_pass http://gateway; + proxy_read_timeout 1800s; + } + + location ~ "^/(ipfs|ipns|api)(/|$)" { + proxy_set_header Host ""; + proxy_pass http://gateway; + proxy_read_timeout 1800s; } location / { + proxy_set_header Host $host; proxy_pass http://gateway; - proxy_set_header Host $proxyhost; proxy_read_timeout 1800s; }