【问题标题】:How to proxy applications with Nginx and Docker如何使用 Nginx 和 Docker 代理应用程序
【发布时间】:2018-11-13 23:47:13
【问题描述】:

我收到一个5#5: *23 upstream timed out (110: Connection timed out) while connecting to upstream, client: nginx 错误。

我已阅读并应用了Nginx reverse proxy causing 504 Gateway Timeout 问题。但是我的情况略有不同,因为我有三个端点要代理。

我的 nginx.conf:

worker_processes 1;

events { worker_connections 1024; }

http {

     server {
        listen       80;
        listen       [::]:80;
        server_name  rollcall;

          location /api {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_pass "http://[hostip]:8080/api";
        }

          location /api/attendance {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_pass "http://[hostip]:8000/api";
      }

           location / {
            include /etc/nginx/mime.types;
            root /usr/share/nginx/html;
            index index.html index.htm;
            try_files $uri $uri/ /index.html =404;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;

                        proxy_read_timeout 3600s;
                        proxy_send_timeout 3600s;


        }
 error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }


  }

}

我的“/”和端口:8080 代理的应用程序正如他们所期望的那样,但是我的端口:8000 的应用程序没有代理,并得到上述超时异常。如果我尝试使用端口:8000 请求应用程序,应用程序将按预期工作。

什么可能导致上述超时,以及我应该如何更改我的 conf 文件?

【问题讨论】:

  • 您能解释一下 docker 在您的场景中的作用吗?

标签: nginx reverse-proxy timeoutexception


【解决方案1】:

问题不是 Nginx 或 Docker 相关问题。应用程序 Droplet 上未打开端口 8000。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 2020-10-31
    相关资源
    最近更新 更多