2013-05-13 40 views
4

我们需要在ubuntu 12.04服务器上部署rails 3.2.12 appsub uri nbhyrails app有3 engines,其中一个是用于用户认证的authentify。主应用程序的根指向验证的登录页面。这里是主要的应用程序的routes.rb中:404未找到部署导轨的错误3.2.12应用程序(带引擎)到nginx/passenger上的SUB URI

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' 

的应用程序部署到与passenger and nginxubuntu 12.04运行基本URI nbhy。在同一台服务器上,还有另一个rails应用程序在其自己的子uri中运行。这里是nginx.conf的配置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; 
    } 
} 

另外一个symlinknbhydocument root/var/www指向/var/www/nbhyop/current/public创建。这里是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轨道并正常工作。

输入http://6.95.225.93/nbhy后会显示login page。输入用户名和密码后,页面被重定向到http://6.95.225.93/authentify/session,出现404 Not Found错误。有一个在nginxerror.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/" 

很明显,因为它缺少wwwauthentify之间的base urinbhy/var/www/authentify/session不会打右页。根据我们的分析,createauthentify session controller未被击中,即使用户名和密码为http://6.95.225.93/nbhy,用户也没有被认证。

还发现用户可以loginhttp://6.95.225.93/nbhy/authentify/session/new与一些扭曲。登录后页面将被重定向到http://6.95.225.93/user_menus,这将抛出404 Not Found错误。但是,如果我们插入nbhy作为:http://6.95.225.93/nbhy/user_menus,那么它将成功调出user menus page。对于任何进一步点击链接,手动插入nbhy将使链接工作(如果nbhy丢失)。

部署时没有使用sub uri,Rails应用工作正常。

为什么sub uri从路由中丢失?有没有办法让nbhy在这里停留并消除错误?感谢帮助。

回答

2

最有可能authentify引擎做一个重定向到/user_menus,而不是/nbhy/authentify。这是你写的定制的Rails或Sinatra应用程序吗?如果是这样,您需要更改/配置authentify的代码,以始终附加托管Rails应用程序的当前子目录。您可以通过在您的代码中说ENV['RAILS_RELATIVE_URL_ROOT']从乘客那里获得。

+0

redirect_to'/ user_menus'。你是对的。用户获得授权后,验证将重定向到/ user_menus,如上所述。我们可以这样做:redirect_to ENV ['RAILS_RELATIVE_URL_ROOT'] +'/ user_menus'?开发线上方是否行? – user938363 2013-05-20 04:00:03

+0

我们也需要把这个相对的url根目录放在应用程序的每个重定向中吗?我们仍然不明白为什么最后2次部署到sub uri工作正常(只需在nginx.conf和symlink中配置上面的配置),并且这个引擎变得如此困难。 – user938363 2013-05-20 04:22:29

+0

不幸的是,你需要使用ENV ['RAILS_RELATIVE_URL_ROOT'] +'/ user/menus''。如果您使用的是Rails路径助手(比如'user_path','login_path'等),那么您没有问题,它们会自动附加相对URL根目录。但是,如果你正在做自己的重定向到自定义路径,那么你需要自己做。 – Subhas 2013-05-20 12:48:28

1

轨道直接从http://6.95.225.93生成路径而不是http://6.95.225.93/nbhy

您可能需要将所有路线的范围限定为“/ nbhy”。

config/routes。RB

scope "/nbhy" do 
    ... 
end 
+0

将再次尝试范围。我们是否也需要保持nginx和symlink中的当前配置? – user938363 2013-05-17 14:15:06

+0

是的,你需要两个。 – depa 2013-05-17 14:32:38

+0

另一个关于routes.rb中的范围的问题:如何处理没有nbhy的开发路线?我们可以做范围“/ nbhy”|| “/”呢? – user938363 2013-05-17 14:56:21

相关问题