Amazon Elastic beanstalk:使用nginx / apache将子域转发到子文件夹

时间:2013-08-19 18:54:50

标签: .htaccess nginx amazon elastic-beanstalk

我在ebs上创建了我的node.js应用程序,其中有两个子路由器'foo'和'bar',目前可通过'example.com/foo'和'example.com/bar'访问。

我希望ebs的反向代理将子域“foo.example.com”和“bar.example.com”转发到这些子文件夹......

即。 “foo.example.com/xxx”改为“example.com/foo/xxx” “bar.example.com/yyy”到“example.com/bar/yyy”等。

我知道如何配置nginx来做到这一点,但我无法想出去访问EBS上的nginx配置文件......

有人问the same thing over a year ago,但似乎EBS已经开发了很多优惠,因为......我想知道现在这种事情是否可行。

1 个答案:

答案 0 :(得分:6)

您可以使用配置文件来自定义您的nginx配置。

  1. 在源包的顶层创建一个.ebextensions目录。
  2. 创建配置文件/your_app/.ebextensions/custom.config。在配置文件中键入以下内容以配置转发设置。 (我创建了一个gist
  3. files:
      "/etc/nginx/conf.d/custom.conf" :
        content: |
          server {
            listen 8080;
            server_name foo.chief-motp.com;
            location / {
              proxy_pass  http://nodejs/foo/;
              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;
             }
             location /public {
               alias /var/app/current/public;
             }
          }
          server {
            listen 8080;
            server_name bar.chief-motp.com;
            location / {
              proxy_pass  http://nodejs/bar/;
              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;
            }
            location /public {
              alias /var/app/current/public;
            }
          }
    

    定制Elastic Beanstalk EC2实例的另一种方法是使用Custom AMI。有关详细信息,请参阅my post