【问题标题】:aws elastic beanstalk nginx reverse proxy settingsaws elastic beanstalk nginx 反向代理设置
【发布时间】:2019-07-30 20:28:21
【问题描述】:

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

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,它运行应用程序

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,在里面我有

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下创建它

文件: /etc/nginx/conf.d/: 所有者:根 组:根 内容:| 上游节点{ 服务器 127.0.0.1:8081; 保活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 / {
          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;
  }

我仍然没有让反向代理工作。

谁能帮帮我?

感谢您的任何帮助和建议。

【问题讨论】:

    标签: amazon-web-services nginx reverse-proxy amazon-elastic-beanstalk


    【解决方案1】:

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

    upstream nodejs {
        server 127.0.0.1:8081;
        keepalive 256;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-18
      • 2020-08-27
      • 2020-11-02
      • 2016-07-05
      • 1970-01-01
      • 2021-08-22
      • 2021-11-24
      • 2017-04-01
      相关资源
      最近更新 更多