Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. The routes.rb is (related only):

  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. Here is the routes.rb in engine authentify:

  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:

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). Why nbhy is missing and how can we put it back in url so user can login from http://mysite.com/nbhy?

Here is the nginx config on ubuntu 12.04 server for the sub uri:

server {
        listen 80;
        server_name mysite.com;
        root /var/www/;
        passenger_enabled on;
        rails_env production;
        passenger_base_uri /nbhy;
}
like image 215
user938363 Avatar asked Jun 06 '13 04:06

user938363


1 Answers

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.

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.

Than all of your rotes are normal.

like image 94
Danpe Avatar answered Oct 17 '22 20:10

Danpe