简体   繁体   English

如何使用sub uri使用passenger / nginx登录rails 3.2.12

[英]How to use sub uri to login in rails 3.2.12 with passenger/nginx

Our Rails 3.2.12 app is hosted under subdirectory /nbhy . 我们的Rails 3.2.12应用程序托管在子目录/nbhy The routes.rb is (related only): routes.rb是(仅相关):

  root :to => "authentify::sessions#new"
  match '/signin',  :to => 'authentify::sessions#new'
  match '/signout', :to => 'authentify::sessions#destroy'

Here authentify is the rails engine which handles user authentication. 这里authentify是处理用户身份验证的rails引擎。 Here is the routes.rb in engine authentify : 这是引擎authentifyroutes.rb

  resource :session
  root :to => 'sessions#new'
  match '/signin',  :to => 'sessions#new'
  match '/signout', :to => 'sessions#destroy'

In order to login we have to use the link: 要登录,我们必须使用以下链接:

http://mysite.com/nbhy/authentify/session/new

But this link is too long and not easy to remember. 但是这个链接太长而且不容易记住。 If we login at: 如果我们登录:

http://mysite.com/nbhy

The system will throw out error 404 Not Found and redirect page to: 系统将抛出错误404 Not Found并将页面重定向到:

http://mysite.com/authentify/session

The problem is that the app is redirecting the login request to /authentify/session which can not be found (missing nbhy). 问题是应用程序正在将登录请求重定向到无法找到的/authentify/session (缺少nbhy)。 Why nbhy is missing and how can we put it back in url so user can login from http://mysite.com/nbhy ? 为什么缺少nbhy,我们如何将其放回url中,以便用户可以从http://mysite.com/nbhy登录?

Here is the nginx config on ubuntu 12.04 server for the sub uri : 这是sub uri ubuntu 12.04 server上的nginx config

server {
        listen 80;
        server_name mysite.com;
        root /var/www/;
        passenger_enabled on;
        rails_env production;
        passenger_base_uri /nbhy;
}

Try: 尝试:

namespace :nbhy do
    match '/signin',  :to => 'authentify::sessions#new', :as => "signin"
    match '/signout', :to => 'authentify::sessions#destroy', :as => "signout"

    root :to => "signin"
end

And remove the base uri from passenger. 并从乘客身上移除基地uri。

Alternatively 另外

You can change the server root: 您可以更改服务器根目录:

server {
    listen 80;
    server_name mysite.com;
    root /var/www/nbhy;
    passenger_enabled on;
    rails_env production;
}

Which is very acceptable and thats what I do in all of my websites. 这是非常可以接受的,这就是我在所有网站上所做的事情。 bacuse it connectes between the domain and the root path. bacuse它连接域和根路径之间。

Than all of your rotes are normal. 比你所有的腐烂都正常。

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

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