簡體   English   中英

ExpressJS / NodeJS-反向代理部署

[英]ExpressJS/NodeJS - Reverse Proxy Deployment

我有3個AngularJS應用程序,每個應用程序都有自己的ExpressJS后端。 如何以這種方式部署所有3個應用程序:

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

附加信息:
-我正在AWS EC2實例中部署應用程序
-我嘗試將應用程序合並到一個ExpressJS應用程序中。 雖然這可行,但我仍然想知道上述情況是否可能

當然可以。 您只需要運行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

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服務器背后Nginx /

您可以設置AWS CloudFront並將每個應用程序設置為Origins。 它提供了從單個域(CloudFront的安裝程序)路由到不同Express應用程序的靈活性,並且還允許在Edge位置緩存靜態內容路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM