【问题标题】:Sidekiq UI is not loading assets - 404 not foundSidekiq UI 未加载资产 - 未找到 404
【发布时间】:2025-12-07 04:05:02
【问题描述】:

我在生产环境中使用 sidekiq 运行 rails 4.1 应用程序。我已经使用 nginx + unicorn 部署了它。我还安装了sidekiq UI,如下所示,

mount Sidekiq::Web => '/sidekiq'

但是自从最近几天我尝试访问 sidekiq UI 时,sidekiq 的所有资产都返回 404,找不到。但它以前工作正常。但无法找到导致 404 的原因。

这是我的设置 我的应用程序的 nginx+unicorn 设置

upstream sample_app {
  server unix:/tmp/sample_app.sock fail_timeout=0;
}

server {
  listen 80;
  server_name www.sample_app.com;

  root /home/deploy/applications/sample_app/current/public;

  # set expire to all assets
  location ~* \.(?:ico|css|js|gif|jpe?g|png|svg)$ {
    expires max;
  }

  try_files $uri/index.html $uri @sample_app;

  location @sample_app {
    proxy_set_header X-Request-Start "t=${msec}";
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://sample_app;
  }

  error_page 500 502 503 504 /500.html;
  error_page 404 413 /404.html;
  client_max_body_size 50M;
  keepalive_timeout 10;
}

【问题讨论】:

    标签: ruby-on-rails nginx unicorn sidekiq


    【解决方案1】:

    调试后,我可以通过添加以下行来解决它

    # set expire to all assets
    location ~* \.(?:ico|css|js|gif|jpe?g|png|svg)$ {
      expires max;
      try_files $uri @sample_app;
    }
    

    【讨论】:

    • 但我不明白这里发生了什么。为什么这个区块会为 sidekiq 资产发送 404。
    • 修改单个 gem 的 web 服务器配置应该是一个可接受的解决方案。