Can a Subdomain Point to a Port or a URL Path?
No, not with DNS alone. A DNS record maps a name such as app.example.com to an address (A or AAAA) or to another name (CNAME); it has no field for a port like :8080 or a path like /app. Browsers connect to port 443 for HTTPS and port 80 for HTTP unless the URL says otherwise. To make app.example.com serve something running on another port or under a path, point the subdomain's DNS at a server and let that server do the routing, usually with a reverse proxy or a redirect. Some newer record types can advertise ports for particular protocols, but they are not a general replacement.
What DNS records can and cannot hold
| Record | Holds | Port or path? |
|---|---|---|
| A / AAAA | An IPv4 or IPv6 address | No |
| CNAME | Another host name | No; a value with / or : is not a valid target |
| SRV | Host name, port, priority and weight for a named service | Port, yes, but only for protocols whose clients look up SRV records; web browsers do not use it for ordinary HTTP |
| HTTPS / SVCB (RFC 9460) | Service parameters, including an optional port, for HTTPS and other services | Defined in the standard, but client support for using it to change ports is limited and should not be relied on |
| TXT | Arbitrary text | No; clients do not route by TXT |
The DNS record types guide and the decision grid for choosing a record type cover each record in more detail.
Option 1: a reverse proxy
The standard answer for a web application running on a non-standard port is a reverse proxy: a web server that listens on ports 80 and 443 and forwards requests for a given host name to the right local port or upstream service.
- Create an A or AAAA record for
app.example.compointing to the server that runs the proxy. - Configure the proxy with a site or virtual host for
app.example.comthat forwards to, for example,http://127.0.0.1:8080. - Obtain a certificate for
app.example.comand terminate HTTPS at the proxy. - Close the application's own port in the firewall, so it is reachable only through the proxy.
| Name | Type | Value | TTL |
|---|---|---|---|
app | A | 203.0.113.10 | 3600 |
The address above is from the documentation range reserved for examples. Many hosting platforms and CDNs offer the same routing as a setting, letting you map a host name to an origin port without running your own proxy. The guide to pointing a subdomain at your own server walks through the server side.
Option 2: a redirect
If you simply want blog.example.com to send visitors to example.com/blog, use an HTTP redirect. Point the subdomain at a server or a redirect service, and have it answer every request with a permanent redirect, keeping the rest of the path where that makes sense. The visitor's address bar will change to the target URL, which is the key difference from a proxy. The guide to redirecting a subdomain to another address covers redirect types, HTTPS on the old name and how to preserve paths.
Option 3: serve a path under the subdomain
Sometimes the goal is the opposite: content that lives at example.com/app should appear at app.example.com without the address changing. That is a reverse proxy again, this time rewriting the path: requests for app.example.com/anything are forwarded to example.com/app/anything. It works, but watch for links, cookies and redirects inside the application that assume the original path. The in-depth guide on moving from a subdomain to a subfolder discusses the trade-offs.
Typing the port still works
For testing or internal tools, you do not need any of this: a URL can carry the port itself, as in https://app.example.com:8443/. DNS resolves the name to an address as usual, and the browser then connects to the port written in the URL. The certificate must still list app.example.com, because certificates are tied to names, not ports. The firewall must allow the port, and users must remember it, which is why public services nearly always sit behind a proxy on the standard ports instead.
"Domain forwarding" and frame forwarding
Many DNS and registrar dashboards offer "URL forwarding" for a subdomain. Behind the scenes, the provider points your record at its own web servers, which then send redirects. That is convenient for simple cases. Some providers also offer "masked" or frame forwarding, which shows the target inside a frame under your name; it tends to break HTTPS, bookmarking and search indexing, and many sites refuse to be framed. Prefer a plain redirect or a proper proxy.
Testing that it works
- Check the DNS answer with
dig app.example.comornslookup app.example.com; it should return the proxy's address. The drill sheet on reading dig output helps. - Request the page with a tool such as
curl -I https://app.example.com/and check the status code and anyLocationheader. - Confirm the certificate covers the exact host name, as explained in why a subdomain shows a certificate error.
Frequently asked questions
Can I put a port in a CNAME record?
No. A CNAME target must be a host name. Values such as server.example.net:8080 are invalid.
Can SRV records make my website load on another port?
Not in ordinary web browsers. SRV is used by protocols such as some messaging and voice services, whose clients look it up.
Is a reverse proxy slower?
The overhead is usually small compared with the application itself, and a proxy brings benefits such as a single place to manage HTTPS.
The SubDoms study hub places this card in the records and pointing module.