0

运行默认图像

#  docker run -d --rm -p 8080:80 nginx

测试(linuxmint 20 | Docker 版本 19.03.12,构建 48a66213fe):

~# curl --verbose http://127.0.0.1:8080/todos
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /todos HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server

测试(macos 10.15.5 | Docker 版本 19.03.12,build 48a66213fe):

curl --verbose http://127.0.0.1:8080/todos
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /todos HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Server: nginx/1.19.1
< Date: Sat, 08 Aug 2020 04:20:15 GMT
< Content-Type: text/html
< Content-Length: 153
< Connection: keep-alive
< 
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.19.1</center>
</body>
</html>
* Connection #0 to host 127.0.0.1 left intact
* Closing connection 0

按照说明安装: https ://docs.docker.com/engine/install/ubuntu/

你能告诉我如何解决吗?

4

1 回答 1

0

Nginx 默认没有定义 urlcurl --verbose http://127.0.0.1:8080/todos

Docker 代理正在工作,因为curl --verbose http://127.0.0.1:8080应该可以工作,将您的主机 localhost :8080 连接到容器内的 nginx :80 。

404 并不意味着 docker-proxy 不起作用,而是在您的 docker 配置中找不到 url。也许你有一个没有添加到 nginx 的 web 代码,或者你错过了一些 nginx 配置。

于 2020-08-09T09:40:01.933 回答