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