首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >aws弹性beanstalk nginx反向代理设置

aws弹性beanstalk nginx反向代理设置
EN

Stack Overflow用户
提问于 2019-03-09 03:02:21
回答 1查看 1.6K关注 0票数 1

我关注了这两个帖子,但没有任何运气

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html

https://davidojeda.mx/blog/2018/01/11/extend-nginx-config-on-aws-elasticbeanstalk

我刚刚开始使用手头的elastic beanstalk

按照基础知识,我用port:8000启动了服务器,我想做一个反向代理,这样它就会监听端口80。

我一开始没有使用elb,因为我想在进入elb之前更多地了解基础知识

这是我的index.js,它运行应用程序

代码语言:javascript
复制
const express = require('express');
const app = express();
const port = 8000;

app.get('/', async (req, res) => {
    return res.json({ status: true });
});

app.listen(port, () => console.log(`Example app listening on port ${port}!`));

如果url是http://eb_self_generated_url:8000,那么上面的代码肯定可以工作,所以我想让它与https://eb_self_generated_url一起工作

我读了一些帖子,但都不管用。

在我的根目录中,我创建了.ebextensions/nginx/conf.d/s_proxy.conf,在里面我有

代码语言:javascript
复制
upstream nodejs {
    server 127.0.0.1:8081;
    keepalive 256;
}

server {
    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 / {
        # this is actually what need to be changed
        # I tried changing from http://nodejs to http://localhost:8000 at server which then will make the reverse proxy work
        proxy_pass  http://localhost:8000;
        proxy_set_header   Connection "";
        proxy_http_version 1.1;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP   $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }

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

我试着压缩上面的和update / deploy,但是什么都没有改变

我还尝试在我的应用程序.ebextensions/proxy.conf下创建此应用程序

files: /etc/nginx/conf.d/: owner: root group: root content:|上游nodejs { server 127.0.0.1:8081;keepalive 256;}

代码语言:javascript
复制
  server {
      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 / {
          proxy_pass  http://localhost:8000;
          proxy_set_header   Connection "";
          proxy_http_version 1.1;
          proxy_set_header        Host            $host;
          proxy_set_header        X-Real-IP $remote_addr;
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      }

      gzip on;
      gzip_comp_level 4;
      gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml appl$

      # Include the Elastic Beanstalk generated locations
      include conf.d/elasticbeanstalk/01_static.conf;
      include conf.d/elasticbeanstalk/healthd.conf;
  }

尽管如此,我还是没能让反向代理正常工作。

有谁能帮我一下吗?

感谢您的帮助和建议。

EN

回答 1

Stack Overflow用户

发布于 2019-04-24 03:57:11

您是否注意到您正在使用nginx配置中的端口8081,而不是您的应用程序的端口(8000)?

代码语言:javascript
复制
upstream nodejs {
    server 127.0.0.1:8081;
    keepalive 256;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55069430

复制
相关文章

相似问题

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