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

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

这正是我想要做的: 在这里输入图像说明

这是named的configuration文件。

/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 

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

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

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

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

Interesting Posts