We need to deploy a rails 3.2.12 app
to sub uri nbhy
on a ubuntu 12.04
server. The rails app
has 3 engines
and one of them is authentify
which is for user authentication. The main app's root pointing to authentify's signin page. Here is the routes.rb in main app:
root :to => "authentify::sessions#new"
match '/signin', :to => 'authentify::sessions#new'
match '/signout', :to => 'authentify::sessions#destroy'
match '/user_menus', :to => 'user_menus#index'
match '/view_handler', :to => 'authentify::application#view_handler'
The app is deployed to base uri nbhy
running on ubuntu 12.04
with passenger and nginx
. On the same server, there is another rails app running in its own sub uri. Here is the configuration in nginx.conf for sub uri nbhy
:
server {
listen 80;
server_name 6.95.225.93;
root /var/www/;
passenger_enabled on;
rails_env production;
passenger_base_uri /by;
passenger_base_uri /nbhy;
#for rails >=3.1, assets pipeline
location ~ ^/assets/ {
expires max;
add_header Cache-Control public;
add_header ETag "";
break;
}
}
Also a symlink
nbhy
is created at document root
/var/www
pointing to /var/www/nbhyop/current/public
. Here is the output of the root /var/www/
:
total 8
lrwxrwxrwx 1 cjadmin www-data 28 Nov 3 2012 by -> /var/www/byop/current/public
drwxrwsr-x 4 cjadmin www-data 4096 Nov 4 2012 byop
lrwxrwxrwx 1 cjadmin www-data 30 May 16 21:27 nbhy -> /var/www/nbhyop/current/public
drwxrwsr-x 4 cjadmin www-data 4096 May 14 15:21 nbhyop
The by
is the first
rails app deployed to the sub URI
and is working fine.
The login page
is displayed after typing http://6.95.225.93/nbhy
. After key in user and password, the page was redirected to http://6.95.225.93/authentify/session
with 404 Not Found
error. There is an error found in nginx
error.log
:
2013/05/13 16:29:25 [error] 2384#0: *1 open() "/var/www/authentify/session" failed (2: No such file or directory), client: 192.168.1.1, server: 6.95.225.93, request: "POST /authentify/session HTTP/1.1", host: "6.95.225.93", referrer: "http://6.95.225.93/nbhy/"
Obviously /var/www/authentify/session
will not hit the right page because it is missing the base uri
nbhy
between www
and authentify
. Based on our analysis, the create
in authentify session controller
hasn't been hit and the user hasn't been authenticated even with the right user name and password at http://6.95.225.93/nbhy
.
Also find out that a user can login
at http://6.95.225.93/nbhy/authentify/session/new
with some twist. After login the page will be redirected to http://6.95.225.93/user_menus
which will throw out 404 Not Found
error. However if we insert nbhy
in between as : http://6.95.225.93/nbhy/user_menus
, then it will bring up the user menus page
successfully. For any further click on links, manually inserting nbhy
will make the link work (if nbhy
is missing).
The rails app worked fine when deploying without sub uri
.
Why the sub uri is missing from route? Is there a way we can make the nbhy
here to stay and eliminate the error? Thanks for help.