大网数据广告活动
网站运营与故障问答

How to set up wildcard subdomain CNAME records for a multi-tenant app?

· 52CE 我爱测

We are trying to point a heroku staging app ( something.herokuapp.com ) to a subdomain on our domain ( staging.company.com ). Everything else on the domain ( *.company.com ) goes to our previous production app. I'm having trouble…

问题原文

原帖链接 · Jaron Gao · CC BY-SA 3.0

We are trying to point a heroku staging app (something.herokuapp.com) to a subdomain on our domain (staging.company.com).

Everything else on the domain (*.company.com) goes to our previous production app.

I'm having trouble pointing subdomains of the subdomain to the heroku staging app. For example, login.staging.company.com should point to staging's login portal, and hospital.staging.company.com should load our app with the Hospital client's data.

I have 3 relevant CNAME records:

  1. * points to company.com. (Everything goes to production)
  2. *.staging points to something.herokuapp.com.
  3. staging also points to something.herokuapp.com.

Current behavior is that login.staging.company.com goes to app.company.com, thus it goes to our production app instead of our heroku staging app. However, login.staging.company.com/users/sign_in goes to our staging app just fine, but it is the ONLY link that is going to our staging app.

Which records do I need to add/remove to make sure that everything under *.staging.company.com goes to our heroku staging app, and everything not under that continues to go to our production app?

Ex. hospital.staging.company.com should go to staging, while government.company.com should go to production.

已采纳解答

原帖链接 · jcaron · CC BY-SA 3.0

Domain hosting has two parts:

  • the DNS must point the domain to a server
  • and the server must recognise the domain

You should verify both.

  1. DNS points the domain to the right server:

    • check using dig (or drill), nslookup or even simply ping or traceroute. All will take a domain name and let you know what the final resolved IP is. Check that it matches what you expect it to be.

    • or you can use online tools like dns.squish.net which will give you a much more detailed view of how the whole process goes.

  2. Server recognises the domain

This is specific to protocols which include the domain in the request (such as HTTP/HTTPS), and is of course vital for virtual hosting (hosting multiple domains on the same server with the same IP). This is something that is configured on the server.

The server must thus recognise all domains you are pointing to it (if you just point a domain to a server using DNS, and the server does not know about it, it'll have a hard time knowing what it should return). Depending on your hosting situation, this may be more or less complex to handle. Also, managing wildcard domains may add another hurdle, depending on whether you actually configure individual sub-domains on the host, or (try to) have it recognise a wildcard as well (not all servers/hosts can).

Once the request gets to the right virtual server, then you may have additional issues with local scripts, .htaccess files, Rewrite Rules, and more, which may not be properly configured and redirect somewhere else.

  • start by using a tool such as curl (with the -v option) to see what happens when you connect to the URL (is there a redirect — or several?)

  • check .htaccess files for Redirect* and RewriteRule directives which may cause the redirect

  • there may be further redirects generated in code, but then we would need a lot more details about what software you are running.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。