amone
amone

Reputation: 3862

How to make a domain work under a specific port?

There is an apache instance running on my server and it uses the port 80. I have also a nodejs application that uses port 8081. Now there're a couple of domains that point to the server. Apache handles all the requests and responds all of them. I want only one of the domains to be responsed by the NodeJS app. In other saying, I want one domain that point to the server to run the NodeJS app.

That's exactly what I want to do: enter image description here

This is the configuration file of the 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";

This is the zone file.

/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.

I added the domain that I want to use with my NodeJS app into the hosts file. But nothing changed. /etc/hosts

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

Upvotes: 1

Views: 657

Answers (2)

aravvn
aravvn

Reputation: 794

As @galkin mentioned, you need to pass the request to the port 8081. Add this into the httpd.conf file.

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

For 503 error, try to run this and restart the apache.

# /usr/sbin/setsebool httpd_can_network_connect 1

Upvotes: 2

galkin
galkin

Reputation: 5519

You need ProxyPass instruction. It will looks like this:

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

Also, usually NGINX + Node.js are used for resolve this issue.

Upvotes: 0

Related Questions