如何解决Nginx 作为 go-ipfs 的代理导致重写循环
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;
}
}
}
我在共享虚拟网络的不同容器中运行 Nginx
和 go-ipfs
。在 Nginx 容器中,我可以让 ipfs
查询工作:
/ # 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!
...
但是向 localhost
发送查询会得到 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>
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"
我不明白循环是从哪里来的。 Nginx 似乎忽略了 proxy_pass
指令并试图将请求传递给自己。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。