gpt4 book ai didi

ruby-on-rails - Rails 4 子域不适用于生产

转载 作者:行者123 更新时间:2023-12-04 22:59:07 25 4
gpt4 key购买 nike

我创建了一个带有 3 个子域的 Rails 4 应用程序。

发展领域:

  • mydomain.dev
  • api.mydomain.dev
  • account.mydomain.dev

  • 生产域(带有乘客的 Ngnix):
  • app.mydomain.com(www.mydomain.com 和 mydomain.com 显示其他页面,而不是应用程序)
  • api.mydomain.com
  • account.mydomain.com

  • 我的 config/routes.rb 看起来像这样:
    Rails.application.routes.draw do
    namespace :api, constraints: { subdomain: 'api' }, path: '/', defaults: { format: :json } do
    namespace :v1 do
    resources :clients, only: [:create, :show]
    end
    end

    namespace :account, constraints: { subdomain: 'account' }, path: '/' do
    get '/:locale' => 'welcome#index', locale: /en|pt/
    root 'welcome#index'

    scope "(:locale)", locale: /en|pt/ do
    get :sign_in, to: 'sessions#new'
    post :sign_in, to: 'sessions#create'
    end
    end

    get '/:locale' => 'welcome#index', locale: /en|pt/
    root 'welcome#index'

    scope "(:locale)", locale: /en|pt/ do
    resource :session, only: [:new, :create, :destroy]
    get :login, to: 'sessions#new', as: :login
    end
    end

    我的 ngnix 虚拟主机文件:
    server {
    listen 80;
    listen [::]:80;

    # SSL configuration
    #
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name mydomain.com api.mydomain.com account.mydomain.com;

    passenger_enabled on;
    passenger_ruby /home/username/.rvm/gems/ruby-2.2.2@myapp/wrappers/ruby;

    root /var/sites/mydomain.com/current/public;

    ssl on;
    ssl_certificate /etc/nginx/ssl/mydomain.com/server.crt;
    ssl_certificate_key /etc/nginx/ssl/mydomain.com/server.key;
    }

    问题是,在我的开发机器(本地主机)或开发环境中,它运行得非常好,正如我所希望的。但是在生产中,我收到了错误:“ The page you were looking for doesn't exist. ”,其中包含以下日志信息:

    访问: https://account.mydomain.com/en/sign_in

    I, [2015-07-29T11:31:07.197635 #25813] INFO -- : Started GET "/en/sign_in" for 0.0.0.0 at 2015-07-29 11:31:07 +0100 F, [2015-07-29T11:31:07.206758 #25813] FATAL -- : ActionController::RoutingError (No route matches [GET] "/en/sign_in"): actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in call'

    newrelic_rpm (3.12.1.298)
    lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in
    call' actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in call'

    newrelic_rpm (3.12.1.298)
    lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in
    call' railties (4.2.3) lib/rails/rack/logger.rb:38:in call_app' railties
    (4.2.3) lib/rails/rack/logger.rb:20:in
    block in call'



    在其他作品中, account.mydomain.com 和 api.mydomain.com 仍然作为我的主域“mydomain.com”(作为同一个域)。

    更新:

    我在我的页面上添加此代码:
    <%= request.domain.inspect %><br>
    <%= request.subdomain.inspect %>

    访问: http://api.mydomain.co.ao
    结果我得到:

    As Domain: "co.ao"

    As Subdomain: "api.mydomain"



    但我这里的子域只有:api

    怎么了?

    最佳答案

    默认

    tld_length = 1

    您需要将域的 tld_length 更新为 2,例如:co.in、co.au

    尝试:
    config.action_dispatch.tld_length = 2

    在配置/环境/production.rb

    Reference

    关于ruby-on-rails - Rails 4 子域不适用于生产,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31698032/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com