2014-11-03 55 views
1

我開發了一個帶rails的api,在localhost中一切正常。 但是當我的API是在督促服務器,我得到的錯誤與我的路線......Rails API路由問題(僅在nginx +獨角獸生產中)

這裏的情景:

  • 我的督促服務器配置了nginx的和麒麟
  • 即時通訊使用的子域,版本我的路線(api.servername/V1 /資源)

的routes.rb文件:

constraints subdomain: 'api' do 
    scope module: 'api' do 
    namespace :v1 do 

     resources :tests, param: :name do 
     member do 
      get 'perform' 
     end 
     end 
     resources :jobs 

    end 
    end 
end 

nginx的的c​​onf文件:

server { 
    listen 80; 
    server_name *.server.com.br; 

    # Application root, as defined previously 
    root rails_public_path; 

    try_files $uri/index.html $uri @app; 

    location @app { 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_pass http://appname; 
    proxy_connect_timeout 1800; 
    proxy_read_timeout 1800; 
    }} 
當我運行在督促 rake routes

,我的路線是有的,但麒麟返回404頁。

回答

2

這似乎是一個TLD問題。它不僅在獨角獸上。 如果您將/ etc/hosts配置爲具有相同的域,則會出現相同的錯誤。

刪除routes.rb中的子域約束將按預期工作。

的routes.rb文件:

# constraints subdomain: 'api' do 
scope module: 'api' do 
    namespace :v1 do 
    resources :tests, param: :name do 
     member do 
     get 'perform' 
     end 
    end 
    resources :jobs 
    end 
end 
# end 
+0

感謝的人!也爲我工作。使用passenger + apache。 – 2015-01-27 13:19:18