使用 Thin 和 nginx 装载的 Sinatra 应用程序未加载资源

发布于 2024-12-27 10:41:04 字数 391 浏览 1 评论 0原文

我有一个简单的 Rails 应用程序,其 Resque 服务器安装在 routes.rb 中,作为

require 'resque/server'
require 'resque_scheduler'


    MyApp::Application.routes.draw do

        authenticate :user do
            mount Resque::Server.new, :at => "/tasks"
        end
        ...
        ...

将应用程序安装在路由中以使用基于设计的身份验证。然而,在生产中,Resque 服务器的资源不会加载,而主 Rails 应用程序的资源会正确加载。

I have a simple Rails app with Resque server mounted in routes.rb as

require 'resque/server'
require 'resque_scheduler'


    MyApp::Application.routes.draw do

        authenticate :user do
            mount Resque::Server.new, :at => "/tasks"
        end
        ...
        ...

Mounted the app in routes to use devise based authentication. In production however, the assets are not loaded for the Resque server while the assets for the main Rails app load properly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

优雅的叶子 2025-01-03 10:41:04

环顾四周后,这对我来说对 nginx 和 Thin 有用:

require 'resque/server'

class SecuredResqueServer < Resque::Server
  set :static, true
  set :root, Resque::Server.root
end

路由文件如下所示:

    require 'resque/server'
    require 'resque_scheduler'
    require './app/secured_resque_server'


    MyApp::Application.routes.draw do
    ...
    ...
    authenticate :user do
        mount SecuredResqueServer.new, :at => "/tasks"
    end
    ...
    ...

更改

config.action_dispatch.x_sendfile_header = "X-Sendfile"

并在 production.rb 中

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

为第三,在某些情况下,nginx 配置为 Rails,如下所示:

server{
        ...
        ...
        location ~*\.(jpeg|jpg|gif|png|ico|css|bmp|js)$ {
                root /PATH_TO_APP/public;
        }
        ...
        ...
      }

其中 PATH_TO_APP 是应用程序根目录的路径。此类位置声明可防止从任何其他位置加载已安装的 rake 应用程序或引擎的资产。因此,需要将其删除/注释掉。

最后,不要忘记使用 Ctrl+F5 强制重新加载页面:)

After looking around this worked for me with nginx and thin:

require 'resque/server'

class SecuredResqueServer < Resque::Server
  set :static, true
  set :root, Resque::Server.root
end

The routes file look as follows:

    require 'resque/server'
    require 'resque_scheduler'
    require './app/secured_resque_server'


    MyApp::Application.routes.draw do
    ...
    ...
    authenticate :user do
        mount SecuredResqueServer.new, :at => "/tasks"
    end
    ...
    ...

and changing

config.action_dispatch.x_sendfile_header = "X-Sendfile"

in production.rb to

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

Thirdly, in some cases nginx is configured for rails as follows:

server{
        ...
        ...
        location ~*\.(jpeg|jpg|gif|png|ico|css|bmp|js)$ {
                root /PATH_TO_APP/public;
        }
        ...
        ...
      }

Where PATH_TO_APP is the path of the application root directory. Such location declaration prevents assets to be loaded from any other location for a mounted rake app or engine. This therefore, needs to be removed/commented out.

Lastly, don't forget to do a Ctrl+F5 to force reload the page :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文