skip to Main Content

I have a simple setup for serving content from a specific CID:

user  nginx;
worker_processes  auto;

events {
    worker_connections  1024;
}

http {
    upstream ipfs {
        server ipfs:8080;
    }
    server {
        listen      8080;
        server_name example.com examplecom.net;
        index       readme;
        location / {
            rewrite     ^/(.*)$ /ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/$1;
            proxy_pass  http://ipfs;
        }
    }
}

I’m running nginx and go-ipfs in separate containers that share a virtual network. Within the nginx container, I am able to get queries to ipfs to work:

/ # curl ipfs:8080/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/readme
Hello and Welcome to IPFS!

██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗  ███████╗
██║██╔═══╝ ██╔══╝  ╚════██║
██║██║     ██║     ███████║
╚═╝╚═╝     ╚═╝     ╚══════╝

If you're seeing this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!

...

However sending a query to localhost results in a 500!

/ # curl localhost:8080/
<html>
<head><title>500 Internal Server Error</title></head>
<body>
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx/1.21.0</center>
</body>
</html>

Upon inspecting the nginx logs, I see there is a rewrite cycle error

2021/06/18 14:44:50 [error] 39#39: *2 rewrite or internal redirection cycle while processing "/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/", client: 127.0.0.1, server: example.com, request: "GET / HTTP/1.1", host: "localhost:8080"
127.0.0.1 - - [18/Jun/2021:14:44:50 +0000] "GET / HTTP/1.1" 500 177 "-" "curl/7.76.1"

I don’t understand where the loop is coming from. It seems like nginx is ignoring the proxy_pass directive and trying to pass the request to itself.

2

Answers


  1. rewrite     ^/(.*)$ /ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/$1 break;
    
    Login or Signup to reply.
  2.   location /ipfs/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc/ {
        proxy_pass http://localhost:8080/;
      }
    

    Should do the job, with extra path and querystring 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search