如何使域在特定端口下工作?

时间:2017-08-14 07:59:25

标签: node.js linux named

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

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

这是命名的配置文件。

/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应用程序一起使用的域添加到hosts文件中。但没有改变。 /etc/hosts

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

2 个答案:

答案 0 :(得分:2)

正如@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

答案 1 :(得分:0)

您需要ProxyPass条指令。它看起来像这样:

<VirtualHost www.domain3.com:80>
    ProxyPreserveHost On
    ProxyRequests off
    ProxyPass / http://localhost:8081/
    ProxyPassReverse / http://localhost:8081/
</VirtualHost>

此外,通常使用NGINX + Node.js来解决此问题。