代码之家  ›  专栏  ›  技术社区  ›  GaborH

如何使用nginx和docker代理应用程序

  •  0
  • GaborH  · 技术社区  · 7 年前

    我得到了一个 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;
            }
    
    
      }
    
    }
    

    My“/”和端口为8080的应用程序按预期代理,但是端口为8000的应用程序不代理,并得到上述超时异常。如果尝试使用端口8000请求应用程序,则应用程序将按预期工作。

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

    1 回复  |  直到 7 年前
        1
  •  0
  •   GaborH    7 年前

    问题不是nginx或docker相关的问题。应用液滴上的端口8000未打开。