Wildcard subdomain for some but not all values on DNSimple - dns

I have an app that is roughly fractured between a server serving front end and one serving an API. We'd like to add a wildcard to catch usernames on the subdomain and direct those to the front end server. So my URLs map like so:
Server that serves front-end files is mapped by https://example.com and https://www.example.com
Server for the API is mapped by https://api.example.com
We also have a forum, demo, etc at domains like https://forum.example.com and https://demo.example.com
Right now this is all straightforward using ALIAS records in DNSimple.
What is the best way to capture https://username.example.com and map it to the front-end server? We will need it to be a wildcard e.g. *.example.com, but we don't want to direct api, forum, demo, etc to that server.
Is there a way to set hierarchies or priorities at the DNS level so that it checks for the named matches first and then moves on to wildcard if nothing is found?

The way to go is exactly the one you considered. You should add a wildcard DNS record
*.example.com
that points to the IP (A) or hostname (CNAME) you want. The rule is that if there is a specific record matching the query, our DNS server will server it. Otherwise, we will fallback to the wildcard.
In other words, if you have a wildcard in place and a client asks for api.example.com, we will serve the api DNS record and not the wildcard. Specific records have higher priorities over wildcards.

Related

How to mask a subdomain URL with CNAME record?

I need to mask the subdomain URL http://3477er.domainB.com with https://sub.domainA.com Both in different servers.
So I create the "sub" alias in domainA server pointing to https://34tter.domainB.com with a CNAME record and waited for its propagation.
I thought I should see http://3477er.domainB.com content when I type http://sub.domainA.com in browser. Instead I get the message DNS_PROBE_FINISHED_NXDOMAIN Isn't this the way a CNAME record works?
Is there any other way to achieve my subdomain masking goal?
If you are receiving a DNS_PROBE_FINISHED_NXDOMAIN error, it means one of the subdomains you listed is not resolving to an IP address. I would test both subdomains here -
https://mxtoolbox.com/DNSLookup.aspx
There are a couple important notes here though -
This will only work if the server on domainB has a binding setup for either any (wildcard) domains (usually bad idea), or a binding specifically for your domainA subdomain.
This will only hide your domainB subdomain on a very basic level, if this is what you need. So, in other words, hiding it from non-tech savvy users. It can't be relied upon if security is a concern, since someone could easily find domainB with a DNS lookup.
To truly mask the 'origin' server, you'd need to implement a proxy. This could either be done by making the requests on your domainB server itself, or by using serverless tech (such as Cloudflare Workers, AWS Lamba, etc.). However, this still won't prevent people making requests directly to domainA if they do discover it.

Put a subfolder onto a different server with CNAME

Here's the situation. Website.com is an ASP site which needs a blog that is to be Wordpress. So the website.com/blog needs to be hosted onto a php-friendly server. The company hosting the ASP site doesn't want to have anything to do with Wordpress so we have to use some of the shared hosting providers.
How do I have the Blog section placed onto an entirely different server? I've heard this is done with CNAME, but I've never used it. Most of the research I've done revolves around subdomains, but I need a subfolder mapping, and there's not much to read about putting subfolders onto different servers with a different IP and everything.
Thanks.
There are a few different options:
you can bring the traffic to your own server and then redirect to
the correct location
you can bring the traffic to your own server and then proxy it to the correct location
you can direct the traffic to the correct location either via full page or an IFRAME type mechanism
Each option has some benefits and drawbacks depending your devs knowledge level and your infrastructure. Regarding subdomains, you could use a combination approach where you, for example, use subdomain.yourdomain.com to point to a server instance (can be the same server or a totally different one) that maps the subdomain.yourdomain.com name to a specific path, usually via Host header.
A CNAME is a function in DNS that says "Whatever thing you wanted to find for this name, use the same thing for that other name instead". When you're working with web stuff the "thing" in there is nearly always an IP address.
That is, what a CNAME can do for you is to say that when a user's web browser tries to look up the IP address for website.com, it will use the IP address for someotherwebsite.com. Note the total absence of anything web-related, like subfolders, in this. CNAMEs work on whole domain names, nothing else. Since you want to serve only a part of the stuff at a particular name from another server, CNAME cannot help you. CNAME is the wrong tool for you problem. Do not taunt happy fun CNAME.
In order to serve website.com/blog from another server than website.com, you pretty much have to do some sort of reverse proxying (where the ASP site's server relays requests between the user and the Wordpress server). It's probably easier and more robust to give the Wordpress site its own name (blog.website.com or something), and redirect to that from website.com/blog, but only you can know if that's politically possible in your case.

Custom Domains for a Simple Web App

I've created a really simple databaseless php application that I want to offer as a hosted solution. I've enable wildcard subdomains so that users can sign up and create a subdomain (e.g. "user.myapp.com"). However, I would like to offer the ability for my users to use a custom domain as well if they prefer. I'm pretty sure this can be accomplished by asking the user to add an A Record to their custom domain pointing to my server's IP, but I'm not sure how to handle the domain on my end once they create an A Record pointing to my server's IP.
So, say a user signs up for my service under "user.myapp.com" and then they decide they want to use a custom domain "someuser.com" instead. My specific question is — once the user adds an A Record to their domain "someuser.com" pointing to my server's IP, how do I tell my server to point that domain to "user.myapp.com"? Or is there an easier way to do this?
You'd need to first setup your server to accept requests from someuser.com, which is entirely different than setting up a wildcard for your server alias (e.g. *.myapp.com). You can have a default vhost handle all the hostnames that no other vhost is setup to handle, but then you're still left with mapping someuser.com to user.myapp.com.
Depending on how you've setup your php application, the user's going to need to enter the custom domain they've registered that they had point to your app, then you'll need to know to do that mapping internally by checking the $_SERVER['HTTP_HOST'] server variable to see what host the request is for, and if it's for someuser.com, then map it to user.myapp.com.

Dynamic subdomain redirection

How do I redirect a dynamic subdomain to the same subdomain on a different domain?
*.example.com to *.example2.com
Can this be handled with Zerigo?
Depending on your exact requirements, you could achieve that with a DNAME record:
For example, you could have the following in your example.com zone file:
example.com. IN DNAME example2.com.
and a pretty standard example2.com zone, you can mostly achieve the effect.
Querying dig www.example.com, you'd get:
example.com. IN DNAME exmaple2.com.
www.example.com. IN CNAME www.exmaple2.com.
However, if you had DNS records that you need directly under either zones, e.g. an A, MX or TXT record, they don't "alias" so you need to store them in both zones.
In any case, DNAME is not supported in most DNS providers (Zerigo included) that only gives you a web interface, so you'd need to run your own DNS server.
In DNS you can not redirect, that is an HTTP function. But what you can do is use CNAMEs. A CNAME take a dns name and under the covers resolves it to another name. For example:
www.example.com resolves to www.example2.com. In the web browser the user will see www.example.com though.
What you will want to do is look into "wilcard CNAME". There is a limitation though. A wildcard CNAME will only point to a single address. This means that:
*.example.com will only ever point to a single address at example.com2 (let's say you pick bang.example2.com)
foo.example.com -> bang.example2.com
bar.example.com -> bang.example2.com
baz.example.com -> bang.example2.com
cux.example.com -> bang.example2.com
It is also important to note that not every DNS provider allows for wildcard CNAMEs. Also, not every DNS server allows wildcard CNAMEs. If you really want to have a wildcard CNAME point to the corresponding entry in example2.com, then you may want to look into powerDNS. It allows for 3rd party plugins written in various languages like lua. It also can be backed by a mysql, postgress, ldap, or a sqlite backed. This means that you can add that functionality yourself if it does not already exist.
Good luck

Custom Subdomain with CNAME Problem

I am having a bit of a struggle grasping how to use custom domains with my app. Its the common case of having an app that assigns users to subdomains, ex. user.theapp.com and they want to use a CNAME so m.theirsite.com resolves to the application. It seems that most services that do this require you to tell them what your custom domain is, and that just adding a CNAME record doesn't work. Steps:
User creates an account.
We tell them they can make a CNAME entry to yourstuff.theapp.com (which is the current location).
This is my confusion. After 1&2 my custom domain still isnt working.. so once the client makes that CNAME record and provides us with "m.theirsite.com", what special magic do we do with it to make those sites "the same"?
Thank you in advance.
Our solution was to use PHP/MySQL to solve this. As normal, you should have the external domain/subdomain CNAME'd to your app, however as you will see, the CNAME entry doesn't need to be to the exact subdomain on the app. Next, you will build an area into your database where a user can tell you what external site they have CNAME'd from. At this point, you will perform most of your authentication on the website based on the HTTP host, either grabbing the subdomain and using it as a client, or checking if the HTTP host is in your list of CNAME's and then referencing the client from there.
What the CNAME does is just point to a server location, so if you are using wildcards in your apache configuration, foo.myapp.com resolves to the same location as bar.myapp.com, but in the app can use the host to pull out the subdomain and find the client ("foo" and "bar"). When using a CNAME, like m.mywebsite.com --cnamed--> foo.myapp.com, the application no longer has that client information in the HTTP host, and as we mentioned, the apache wildcard setup (*.myapp.com) just tosses out the subdomain.. so because of this the client must tell us "I will be visiting from m.mywebsite.com, so make that a valid host name for my authentication as well."

Resources