How to redirect a subdomain to the main server address along with a port?

I want to redirect subdomain.domain.tld to my IPaddress:port . The domain.tld is already pointed to the server IP address. Can I do it just by adding an srv record? I am using apache2 and ubuntu. Do I need to redirect, use virtual host ? Since I am a newbie would be really thankful to the precise process. If thats too much to ask can someone point me to the relevant information page.
Thanks in advance
Gaurav

1 Reply

Redirecting a subdomain to a specific port on the your main server can be done by creating an SRV record in addition to your A record, but there is also a method that can be performed using a Virtual Host file.

SRV Record

The SRV record will define the transport protocol, port number, priority, and target for a specific service running on your domain.

You can use the Linode DNS Manager to set up your SRV record.

Service: _service.
Protocol: tcp
Priority: 10
Weight: 30
Port: 5060
Target: .example.com
TTL: Default

Depending upon your desired port and priority, you SRV record will resemble something like this:

_service._tcp.example.com  SRV   10    30    5060  service.example.com

For more information on how to set up an SRV record, you can review the SRV section of Linode's DNS Records Guide Page.

Virtual Host File

It is also possible for you to redirect your subdomain to a specific port on the server using a Virtual Host file. Similar to the SRV record method, you'll need to specify the service, target, and port number in the VH file:

<VirtualHost *:80>
        ServerAdmin admin@example.com
        ServerName subdomain.example.com
        ServerAlias subdomain.example.com
        ProxyRequests Off

        #ProxyPass / http://localhost:8080/
        <Location />
                ProxyPreserveHost On
                ProxyPass http://example.com:8080/
                ProxyPassReverse http://example.com:8080/
        </Location>
     # Uncomment the line below if your site uses SSL.
     #SSLProxyEngine On
</VirtualHost>

For more information on how to configure a Virtual Host file for subdomain redirects, I'd recommend checking out this Q&A site Subdomain to Port redirect. Good luck!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct