首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >弹性豆杆+ Nginx + Node + React 502网关

弹性豆杆+ Nginx + Node + React 502网关
EN

Stack Overflow用户
提问于 2020-11-30 06:56:11
回答 1查看 524关注 0票数 3

我有以下堆栈:

  • 节点后端构建
  • 反应前端构建

我想把它们部署到ELB应用程序中。

当我这样做并尝试访问实例时,我得到的是502坏网关nginx/1.18.0,而不是主页。

后端在8081端口上启动和运行(通过邮递员发出外部请求并正常工作)

问题在于静态内容。

下面是我为proxy.config文件编写的代码(nginx的eb扩展名)

代码语言:javascript
复制
  /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"```
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-30 07:03:01

您要设置的nginx配置文件(/etc/nginx/conf.d/proxy.conf)用于Amazon 1 (AL1)。

对于AL2,应该使用以下方法提供(aws博士) nginx配置文件:

  • .platform/nginx/conf.d/

或者,如果要覆盖主nginx配置文件,请使用

  • .platform/nginx/nginx.conf
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65069217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档