【发布时间】: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