node.js - 如何让域在特定端口下工作?

标签 node.js linux named

我的服务器上运行着一个 apache 实例,它使用端口 80。我还有一个使用端口 8081 的 nodejs 应用程序。现在有几个域指向服务器。 Apache 处理所有请求并响应所有请求。我只希望 NodeJS 应用程序响应其中一个域。换句话说,我想要一个指向服务器的域来运行 NodeJS 应用程序。

这正是我想要做的: enter image description here

这是named的配置文件。

/etc/named.conf

options {
        #listen-on port 53 { 127.0.0.1; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { any; };
        allow-transfer { localhost; ip-address; };
        /*
         - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
         - If you are building a RECURSIVE (caching) DNS server, you need to enable
           recursion.
         - If your recursive DNS server has a public IP address, you MUST enable access
           control to limit queries to your legitimate users. Failing to do so will
           cause your server to become part of large scale DNS amplification
           attacks. Implementing BCP38 within your network would greatly
           reduce such attack surface
        */
        recursion no;

        dnssec-enable yes;
        dnssec-validation yes;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";

        pid-file "/run/named/named.pid";
        session-keyfile "/run/named/session.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
        type hint;
        file "named.ca";
};
zone “maindomain.com” IN {
        type master;
        file “maindomain.com.zone”;
        allow-update { none; };
};  
zone “domain1.com” IN {
        type master;
        file “domain1.com.zone”;
        allow-update { none; };
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

这是区域文件。

/etc/named/domain1.com.zone

$TTL 86400
@       IN      SOA     ns1.maindomain.com. maindomain.com. (
        2013042201
        3600
        1800
        604800
        86400
)

        IN      NS      ns1. maindomain.com.
        IN      NS      ns2. maindomain.com.

@       IN      A       ip
www     IN      A       ip
*       IN      A       ip
_http._tcp.domain1.com.    IN      SRV     0       5       8081    domain1.com.

我将要与我的 NodeJS 应用程序一起使用的域添加到主机文件中。但是什么都没有改变。 /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
ip::8081             domain1.com

最佳答案

正如@galkin 提到的,您需要将请求传递到端口 8081。将其添加到 httpd.conf 文件中。

<VirtualHost *:80> 
ServerAlias domain1.com 
ProxyPass / http://ip-addresss:8081/ 
</VirtualHost>

对于 503 错误,尝试运行它并重新启动 apache。

#/usr/sbin/setsebool httpd_can_network_connect 1

关于node.js - 如何让域在特定端口下工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45669924/

相关文章:

javascript - 如何在 ExpressJS 中使用 Q Promise?

java - Bash 脚本无法将 Java 程序作为 cron 作业运行

linux - 测试文件中的每一行是否包含另一个文件中的多个字符串之一

ruby-on-rails - Rails,将许多命名路由路由到一个操作

javascript - 以编程方式将参数传递给 grunt 任务?

node.js - 有没有办法在 Heroku 上运行非 Web Node.js 应用程序?

node.js - 如何在 Mongoose 中动态地将值插入对象的属性?

linux - 每个月的 1 和 15 执行一次 Crontab

dns - NS : got insecure response; parent indicates it should be secure

xml - 混合 JPA 注释和 XML 配置