heroku上的通配符域 [英] Wildcard domains on heroku

查看:86
本文介绍了heroku上的通配符域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在Heroku上使用通配符域?我的应用程序使用的是子域名。



我跟踪了Heroku自定义域名文章,并将我的 *。mydomain.com myapp.herokuapp.com 。当我访问 dev.mydomain.com 时,它指向了heroku应用程序,但是在Heroku应用程序中,我找不到子域。



总之我想在heroku上使用子域名,比如 dev.myapp.herokuapp.com 。任何建议?

解决方案

Heroku上的通配符设置指示Heroku将任何给定域的子域的请求指向您的应用程序。 / p>

但是这里停止了Heroku的责任。然后,您的应用程序必须能够在应用程序级别处理这些请求。



在Rails中,您可以使用请求控制器中的对象。您可以使用 request.subdomain 访问特定的子域名。

所以,例如,如果您添加了 *。example.com 和某人访问 foo.example.com ,请求对象将使用以下值进行响应:

  request.host 
#=> foo.example.com
request.subdomain
#=> foo

现在您有责任根据您要实现的目标在您的应用中使用这些信息。

How can I use wildcard domain on Heroku? My application is using subdomain.

I followed the Heroku custom domain article and mapped my *.mydomain.com to myapp.herokuapp.com. When I visit dev.mydomain.com it points to heroku app but on Heroku app I cant find the subdomain.

In short I want to use subdomain on heroku, like dev.myapp.herokuapp.com. Any suggestions?

解决方案

The wildcard setup on Heroku instructs Heroku to point any request for a subdomain of given domain to your application.

But here stops Heroku responsibility. Then your application must be able to handle such requests at application level.

In Rails, you can inspect the request details with the request object in your controller. And you can access the specific subdomain with request.subdomain.

So, for example, if you added *.example.com and someone access foo.example.com, the request object will respond with the following values:

request.host
# => foo.example.com
request.subdomain
# => foo

Now it's your responsibility to use such information in your app according to what you are trying to achieve.

这篇关于heroku上的通配符域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆