【问题标题】:ExpressJS/NodeJS - Reverse Proxy DeploymentExpressJS/NodeJS - 反向代理部署
【发布时间】:2017-06-01 09:38:36
【问题描述】:

我有 3 个 AngularJS 应用程序,每个应用程序都有自己的 ExpressJS 后端。您如何以这种方式部署所有 3 个应用程序:

http://myapp.com/<app1>
http://myapp.com/<app2>
http://myapp.com/<app3>

其他信息:
- 我正在 AWS EC2 实例中部署应用程序
- 我尝试将应用程序合并到一个 ExpressJS 应用程序中。虽然这可行,但我仍然想知道上述情况是否可行

【问题讨论】:

    标签: angularjs node.js amazon-web-services express amazon-ec2


    【解决方案1】:

    当然可以。您只需要运行 NGINX 或 Apche 作为反向代理即可。

    假设您的节点应用程序在本地端口 3000、3001 和 3002 上运行,您将设置一个 .conf 文件,其中包含位置标签的上游服务器,如下所示:

    。 . . 位置 /app1 { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header 升级 $http_upgrade; proxy_set_header 连接“升级”; proxy_set_header 主机 $host; proxy_cache_bypass $http_upgrade; }

    . . .
    location /app2 {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
    

    }

    在此处阅读更多详细信息:https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

    【讨论】:

      【解决方案2】:
      server {
          listen 80;
          server_name es.domain.com;
          location /app1 {
              rewrite ^/(.*) /$1 break;
              proxy_ignore_client_abort on;
              proxy_pass http://localhost:3001;
              proxy_redirect http://localhost:3001 https://es.domain.com/appw;
              proxy_set_header  X-Real-IP  $remote_addr;
              proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header  Host $http_host;
              auth_basic "Elasticsearch Authentication";
              auth_basic_user_file /etc/elasticsearch/user.pwd;
      }
      
          location /app2 {
              rewrite ^/(.*) /$1 break;
              proxy_ignore_client_abort on;
              proxy_pass http://localhost:3002;
              proxy_redirect http://localhost:3002 https://es.domain.com/app2;
              proxy_set_header  X-Real-IP  $remote_addr;
              proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header  Host $http_host;
              auth_basic "Elasticsearch Authentication";
              auth_basic_user_file /etc/elasticsearch/user.pwd;
      }
      }
      

      请参考此链接 http://www.minvolai.com/blog/2014/08/Setting-up-a-Secure-Single-Node-Elasticsearch-server-behind-Nginx/Setting-up-a-Secure-Single-Node-Elasticsearch-server-behind-Nginx/

      【讨论】:

        【解决方案3】:

        您可以设置AWS CloudFront 并将每个应用程序设置为 Origins。它提供了从单个域(CloudFront 设置)路由到不同 Express 应用程序的灵活性,还允许在边缘位置缓存静态内容路径。

        【讨论】:

          猜你喜欢
          • 2017-12-20
          • 1970-01-01
          • 2019-07-04
          • 2017-12-02
          • 2010-11-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-12-18
          相关资源
          最近更新 更多