将Rails 3.2.12应用程序(带有引擎)部署到nginx/passenger上的SUB URI时出现404 Not Found错误 [英] 404 Not Found error in deploying rails 3.2.12 app (with engines) to SUB URI on nginx/passenger

查看:49
本文介绍了将Rails 3.2.12应用程序(带有引擎)部署到nginx/passenger上的SUB URI时出现404 Not Found错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要在ubuntu 12.04服务器上将rails 3.2.12 app部署到sub uri nbhy. rails app具有3个engines,其中之一是authentify,用于用户身份验证.主应用程序的根目录指向authentify的登录页面.这是主应用程序中的routes.rb:

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'

该应用程序已部署到在ubuntu 12.04passenger and nginx上运行的uri nbhy上.在同一服务器上,另一个rails应用程序在其自己的sub uri中运行.这是nginx.conf中sub uri nbhy的配置:

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;
   }
}

还在document root /var/www指向/var/www/nbhyop/current/public的位置创建了symlink nbhy.这是root /var/www/的输出:

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

by是部署到sub URIfirst rails应用程序,并且运行正常.

The by is the first rails app deployed to the sub URI and is working fine.

键入http://6.95.225.93/nbhy后将显示login page.输入用户名和密码后,页面被重定向到http://6.95.225.93/authentify/session并出现404 Not Found错误.在nginx error.log中发现错误:

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/"

很显然,/var/www/authentify/session不会找到正确的页面,因为它缺少wwwauthentify之间的base uri nbhy.根据我们的分析,即使在http://6.95.225.93/nbhy处使用正确的用户名和密码,也未单击authentify session controller中的create,也未对用户进行身份验证.

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.

还发现用户可以稍稍曲折地在http://6.95.225.93/nbhy/authentify/session/newlogin.登录后,页面将被重定向到http://6.95.225.93/user_menus,这将抛出404 Not Found错误.但是,如果我们在中间插入nbhy作为http://6.95.225.93/nbhy/user_menus,则它将成功调出user menus page.对于任何进一步的链接单击,手动插入nbhy将使链接有效(如果缺少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).

在没有sub uri的情况下进行部署时,rails应用程序运行良好.

The rails app worked fine when deploying without sub uri.

为什么路线中缺少sub uri?有什么办法可以使nbhy停留并消除错误?感谢您的帮助.

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.

推荐答案

authentify引擎很可能正在重定向到/user_menus,而不是/nbhy/authentify.这是您编写的自定义Rails或Sinatra应用程序吗?如果是这样,则需要更改/配置authentify的代码,以始终附加托管Rails应用程序所在的当前子目录.您可以在代码中说出ENV['RAILS_RELATIVE_URL_ROOT']来从乘客那里得到.

Most likely the authentify engine is doing a redirect to /user_menus, instead of /nbhy/authentify. Is this a custom Rails or Sinatra app that you have written? If so, you need to change/configure the code of authentify to always append the current subdirectory under which the Rails app is hosted. You can get that from passenger by saying ENV['RAILS_RELATIVE_URL_ROOT'] in your code.

这篇关于将Rails 3.2.12应用程序(带有引擎)部署到nginx/passenger上的SUB URI时出现404 Not Found错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆