【问题标题】:Always request becomes not found method on Sinatra and Unicorn and Nginx在 Sinatra 和 Unicorn 和 Nginx 上总是请求变得找不到方法
【发布时间】:2015-10-19 22:15:27
【问题描述】:

要部署在 Sinatra 和 Unicorn 和 nginx 中,当你访问相应的 URL 时,总是会请求变成“not_found do”的方法。

(例如:hogehoge.com/test/)

但是,当我在本地测试时,它会正确进入“get '/' do”方法。

您认为某处有问题吗?

请告诉我。

[test.rb]

# coding: utf-8
require "sinatra"
require 'unicorn'
class Main < Sinatra::Application
 get '/' do
  'Success'
 end

 not_found do
  'not_found'
 end
end

[config.ru]

require './test'
run Main

[unicorn.rb]

@dir = "/var/www/Test"
worker_processes 2
working_directory @dir
preload_app true
timeout 30
listen "#{@dir}/tmp/test.sock", :backlog => 64
pid "#{@dir}/tmp/pids/unicorn.pid"
stderr_path "#{@dir}/log/unicorn.stderr.log"
stdout_path "#{@dir}/log/unicorn.stdout.log"

[nginx.conf]

location /test {
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://Test;
        }

upstream Test {
       server unix:/var/www/Test/tmp/test.sock;
    }

【问题讨论】:

  • 我不使用 Unicorn,但快速阅读他们的首页显示这不是在其下启动进程的通常方式。不要require它来自test.rb;只需使用unicorn -c unicorn.rb 从命令行运行它。首先没有 nginx 也可能更容易测试它;所以在端口而不是 Unix 套接字上启动 unicorn 并 cURL 以查看您的端点是否正确解析。

标签: ruby nginx sinatra unicorn


【解决方案1】:

不同的nginx路径和rb路径

(例如:hogehoge.com/test/)

[test.rb]

# coding: utf-8
require "sinatra"
require 'unicorn'
class Main < Sinatra::Application
 get '/' do
  'Success'
 end

 get '/test' do
  'test Success'
 end

 not_found do
  'not_found'
 end
end

添加

 get '/test' do
  'test Success'
 end

【讨论】:

  • Greeeeeeeeeat!非常感谢!
猜你喜欢
  • 1970-01-01
  • 2016-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-21
  • 2011-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多