[英]Nginx proxy_reverse for docker container
I am currently trying to deploy my app backend as Docker container with exposed ports to my root server.我目前正在尝试将我的应用后端部署为 Docker 容器,并将端口暴露到我的根服务器。
If I am trying to curl the backend with http://example.com:3000
I get an timeout, if I try it through nginx (view config underneath) I get an empty response ( curl: (52) Empty reply from server
). If I am trying to curl the backend with http://example.com:3000
I get an timeout, if I try it through nginx (view config underneath) I get an empty response ( curl: (52) Empty reply from server
) .
server {
listen 443 ssl;
server_name www.example.com example.com;
client_max_body_size 50m;
ssl_certificate ... # managed by Certbot
ssl_certificate_key ... # managed by Certbot
location /backend/ {
proxy_pass http://localhost:3000/;
}
}
However if I try to curl it from the server itself I have no problems.但是,如果我尝试从服务器本身 curl 它我没有问题。
Here is the relevant output of the docker ps
command:下面是docker ps
命令的相关 output:
COMMAND CREATED STATUS PORTS NAMES
"node dist/server.js" 9 minutes ago Up 8 minutes 0.0.0.0:9100->3000/tcp backend
Curl expected (works when running on root server):预期 Curl(在根服务器上运行时有效):
$ curl http://localhost:3000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>
You nginx is running ssl (port 443), so your curl should be:你 nginx 正在运行 ssl (端口 443),所以你的 curl 应该是:
curl -i https://example.com/backend/
. curl -i https://example.com/backend/
。
dont specify any backend port .不要指定任何后端端口。
The problem was iptables on my server.问题是我服务器上的 iptables。 Some rules were deleted resulting in a violated Docker configuration.删除了一些规则,导致违反 Docker 配置。
A simple sudo service docker stop
was the trick.一个简单的sudo service docker stop
就是诀窍。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.