You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ECS中Nginx反向代理异常指向未知主机问题求助

AWS ECS中Nginx反向代理数天后异常指向未知主机问题

我在AWS ECS中部署了包含静态网页与Nginx反向代理的容器,基础镜像采用nginx:alpine。该Nginx既用于提供静态网站服务,也作为VPC后方ECS内另一服务的反向代理,ECS前端配置有AWS负载均衡。

Nginx配置文件

/etc/nginx/nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    resolver 8.8.8.8 valid=60s;
    resolver_timeout 5s;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    upstream backend {
        server api.com:443;
        keepalive 32;
    }
#    proxy_read_timeout 10s;
#    proxy_connect_timeout 10s;
#    proxy_send_timeout 10s;
#    send_timeout 10s;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/default.conf

server {
    listen 3000;
    server_name web.com;

    location / {
        root /usr/share/nginx/html;
        index index.html;
        try_files $uri /index.html;
    }

    location /intools/ {
        client_max_body_size 50M;
        proxy_pass https://api.com;
        proxy_set_header Host api.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Authorization $http_authorization;

        proxy_http_version 1.1;
        proxy_set_header Connection "";

        proxy_connect_timeout 10s;
        proxy_send_timeout 10s;
        proxy_read_timeout 10s;
        send_timeout 10s;

        access_log /dev/stdout;
        error_log /dev/stderr debug;
    }

    location /api/ {
        proxy_pass https://api.com;
        proxy_set_header Host api.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Authorization $http_authorization;

        proxy_http_version 1.1;
        proxy_set_header Connection "";

        proxy_connect_timeout 10s;
        proxy_send_timeout 10s;
        proxy_read_timeout 10s;
        send_timeout 10s;

        access_log /dev/stdout;
        error_log /dev/stderr debug;
    }
}

问题表现

首次部署运行正常,但数天后Nginx出现异常:原本应指向api.com的路由意外重定向至随机未知主机,该问题频繁发生。每次重启ECS容器后可正常运行一段时间,但之后会再次出现指向未知主机的情况。

错误反馈

  • 权限错误:
    {
      "Message": "User: anonymous is not authorized to perform: es:ESHttpGet because no resource-based policy allows the es:ESHttpGet action"
    }
    
  • 404错误:
    404 Not Found
    nginx
    
  • Nginx跳转异常截图:
    Nginx异常跳转至未知主机截图

请问有人遇到过类似问题吗?


内容的提问来源于stack exchange,提问作者BIlly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 16:33:21