简体   繁体   English

Rails redirect_to重定向到https:// subdomain

[英]Rails redirect_to is redirecting to https://subdomain

I just set up cloudflare ssl on top of my website, and now whenever redirect_to @thing is called in rails the client redirects to https://subdomain/thing/1 rather than https://subdomain.domain.com/thing/1 . 我只是在网站顶部设置了cloudflare ssl,现在只要在rails中调用redirect_to @thing ,客户端就会重定向到https://subdomain/thing/1而不是https://subdomain.domain.com/thing/1 not sure if I need to change the cloudflare A records now that ssl is setup because the A record I had before CNAME | subdomain | host 我不确定是否现在已设置ssl来更改cloudflare A记录,因为我在CNAME | subdomain | host之前拥有A记录CNAME | subdomain | host CNAME | subdomain | host CNAME | subdomain | host isn't working anymore. CNAME | subdomain | host不再工作。 If any more information is necessary please let me know! 如果需要更多信息,请告诉我!

Rails server is started like so rails s -p 3000 -b0.0.0.0 -e production 像这样启动Rails服务器rails s -p 3000 -b0.0.0.0 -e production

DNS records are CNAME | subdomain | host A | domain | serverip A | www | serverip DNS记录是CNAME | subdomain | host A | domain | serverip A | www | serverip CNAME | subdomain | host A | domain | serverip A | www | serverip

The rails server is running at serverip:3000 and nginx is routing all traffic with the specific subdomain to this port. Rails服务器运行在serverip:3000 ,nginx将所有具有特定子域的流量路由到该端口。 There are no redirect issues if everything is done using serverip:3000 , but when I do actions using subdomain.domain.com the redirect issues reappear 如果一切都使用serverip:3000完成,则没有重定向问题,但是当我使用subdomain.domain.com进行操作时,重定向问题再次出现

nginx config ``` nginx配置```

server {
    listen 80;
    server_name subdomain.domain.com;
    location / {
        proxy_pass http://subdomain;
    }
}

upstream subdomain {
    server 127.0.0.1:3000;
}

``` ```

you can add following changes routes.rb 您可以添加以下更改routes.rb

constraints subdomain: false do
  get ':any', to: redirect(subdomain: 'www', path: '/%{any}'), any: /.*/
end

You can set the number of top-level domains as an argument to subdomain, eg: 您可以将顶级域的数量设置为子域的参数,例如:

>> app.get('http://www.localhost')
>> app.request.subdomain
=> "" 
>> app.request.subdomain(0)
=> "www" 

This can also be set in an environment file as well: 也可以在环境文件中进行设置:

# config/environments/development.rb
config.action_dispatch.tld_length = 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM