【问题标题】:Run multiple Node js apps on single EC2 instance on different port在不同端口上的单个 EC2 实例上运行多个 Node js 应用程序
【发布时间】:2020-06-04 21:23:08
【问题描述】:

这是我的节点文件

我在/ 上有 HTML

/app上的节点应用程序


server {
    listen 80;
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name localhost;

    ssl_certificate "/etc/letsencrypt/live/xxxxx/fullchain.pem";
    ssl_certificate_key "/etc/letsencrypt/live/xxxxxxx/privkey.pem";
    # It is *strongly* recommended to generate unique DH parameters
    # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048
    #ssl_dhparam "/etc/pki/nginx/dhparams.pem";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aD$
    ssl_prefer_server_ciphers on;


        location / {
        # This would be the directory where your frontend code resides
        root /usr/share/nginx/html;
        index index.html;
        try_files $uri $uri/ =404;
        }

        location /api {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        }
}

server {
    listen 80;
    listen [::]:80;
    server_name localhost;
    return 302 https://xxxxx.com;
}

我也转发了3000端口到80;

我想在这台服务器上的不同端口上运行多个应用程序。

我应该为其他应用设置什么配置。

【问题讨论】:

    标签: javascript node.js nginx amazon-ec2


    【解决方案1】:

    这是 Nginx 配置文件。

    问题是您到底想要达到什么目标。

    1. 场景:不同的域 使用不同的server_name app1.comserver_name app2.com 等向 NGINX 添加更多配置文件……每个配置都应该转发到不同端口上的另一个 Node 应用程序。

    2. 场景:一个域和不同的 PATH。 乘以位置段落。例如。在现有的配置文件中添加新的location /app1paragraph,它将转发到不同端口上的节点应用程序。

    【讨论】:

    • 对于第二种情况,我还必须在我的域 DNS 中将 A 记录添加到 IP。
    • 如果场景相同 ip 但端口不同。有可能吗?
    • 是的,不同的端口是调度流量的最简单方法。只需在容器配置中添加ports即可。
    猜你喜欢
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 2013-01-08
    • 2020-04-02
    • 2014-05-11
    • 2013-05-09
    • 1970-01-01
    • 2016-07-08
    相关资源
    最近更新 更多