簡體   English   中英

Elastic Beanstalk + Nginx + 節點 + React 502 badegateway

[英]Elastic Beanstalk + Nginx + Node + React 502 badegateway

我有以下堆棧:

  • 節點后端構建
  • 反應前端構建

我想將它們部署到 ELB 應用程序中。

當我這樣做並嘗試訪問實例時,我得到502 Bad Gateway nginx/1.18.0而不是主頁。

后端已啟動並在端口 8081 上運行(通過 postman 發出外部請求並正常工作)

問題在於 static 內容。

這是我的proxy.config文件代碼(nginx 的 ebextensions)

  /etc/nginx/conf.d/proxy.conf:
    owner: root
    group: root
    mode: "000644"
    content: |
        upstream nodejs {
            server 127.0.0.1:8081;
            keepalive 32;
        }

        server {
            root /var/app/current/react_build;
            listen 8080;

            if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
                set $year $1;
                set $month $2;
                set $day $3;
                set $hour $4;
            }
            access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
            access_log  /var/log/nginx/access.log  main;

            location /api/ {
                proxy_pass  http://nodejs;
                proxy_http_version 1.1;
                proxy_set_header     Connection      "";
                proxy_set_header     Host            $host;
                proxy_set_header     X-Real-IP       $remote_addr;
                proxy_set_header     X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size 10M;
            }

            location /static/ {
            }

            location / {
                try_files '' /index.html =404;
            }

            gzip on;
            gzip_comp_level 4;
            gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        }

  /opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh:
    owner: root
    group: root
    mode: "000755"
    content: |
      #!/bin/bash -xe
      rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
      service nginx stop 
      service nginx start

container_commands:
 removeconfig:
    command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"```

您嘗試設置的nginx配置文件 ( /etc/nginx/conf.d/proxy.conf ) 適用於Amazon Linux 1 (AL1)。

對於 AL2,應使用以下命令提供nginx配置文件( aws 文檔):

  • .platform/nginx/conf.d/

或者如果你想覆蓋主nginx配置文件,使用

  • .platform/nginx/nginx.conf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM