【问题标题】:Hosting multiple node.js instances on nginx在 nginx 上托管多个 node.js 实例
【发布时间】:2021-02-17 00:15:29
【问题描述】:

大家好,我有一个 Rasberry Pi 4,我希望使用 Nginx 托管多个 node.js 网站,现在我有一个运行良好并连接到 Cloudflare 的实例。

下面的当前“默认”文件

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        server_name example.com www.example.com;

        location / {
                proxy_pass http://localhost:5085;
                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;
        }
}

现在我需要在这里再托管 2 个网站,它们是 - example1.com 在 localhost:3000 上运行 & example2.com 在 localhost:4000 上运行

在这之后,我又有了一个疑问,我需要将这两个添加到 Cloudflare。

在图片一中,我只需将用于端口转发的公共 IP 地址放在端口 80 这是一张图片

现在我将如何将主机连接到 cloudflare。有人可以帮忙吗?

【问题讨论】:

    标签: node.js nginx web proxypass


    【解决方案1】:

    您只需复制当前的 nginx 服务器配置并将 server_name 属性更改为 server_name example2.com 并相应地更改 proxy_pass 目标。

    它看起来像这样:

    # example.com server/proxy
    server {
       listen 80 default_server;
       listen [::]:80 default_server;
    
       server_name example.com www.example.com;
    
       location / {
           proxy_pass http://localhost:5085;
           # ...
       }
    }
    
    # example2.com server/proxy
    server {
       listen 80;       # we removed the default_server tag here   
       listen [::]:80;  # because it can only be used once  
    
       server_name example2.com www.example2.com;
    
       location / {
           proxy_pass http://localhost:1234;
           # ...
       }
    }
    

    【讨论】:

    • 嘿,谢谢!但是,如何将其添加到 Cloudflare?
    • 我会在 cloudflare DNS 中添加什么内容
    • 第二个域与第一个域相同
    • 谢谢,我搞定了!我很快就会制作一个关于这个主题的视频!
    猜你喜欢
    • 2013-07-29
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    • 2012-02-24
    • 2017-05-09
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多