设置 Sinatra 在子目录中运行
现在我对 Sinatra/Ruby/Apache 还很陌生,但继承了一个 Sinatra 应用程序来部署。
目前 Apache 设置为从文档根 (httpdocs) 运行,我需要在文件夹子目录下运行 ruby 应用程序,例如: /httpdocs/webapp
我需要做什么才能在子目录下启动并运行它?
Now I am pretty new to Sinatra/Ruby/Apache but have inherited a Sinatra application to deploy.
Currently Apache is set up to run from a document root (httpdocs) and I need to run a ruby application underneath a folder subdirectory such as: /httpdocs/webapp
What do I need to do to get this up and running under a subdirectory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此链接可能会有所帮助,它解释了如何使用 Passenger (mod_rack) 通过 Apache 部署 Sinatra 应用程序:
部署带有 Apache 和 Phusion Passenger 的 Sinatra 应用程序
您特别感兴趣的部分是虚拟主机配置中的
RackBaseURI
选项。官方文档可以在这里找到:Phusion Passenger 用户指南 - 将机架部署到子 URI
This link might be helpful, it explains how to deploy a Sinatra app with Apache using Passenger (mod_rack):
Deploying a Sinatra App with Apache and Phusion Passenger
The part of particular interest to you is the
RackBaseURI
option in the virtual host configuration. The official documentation is available here:Phusion Passenger users guide - Deploying Rack to Sub URI
我刚刚遇到了同样的问题。由于这里没有关于如何在没有 Passenger 的情况下执行此操作的答案,因此我将记录 Apache + CGI 或 FastCGI 的解决方案。
诀窍是为 Rack 重写
PATH_INFO
,一切都会就位:设置
.htaccess
:在您的 Sinatra 代码中,首先:
现在,所有像
/subfolder/resource/123
这样的 URL 都将在 Sinatra 应用程序中找到正确的路由。在上述情况下,假设 Sinatra 应用程序已放入
/subfolder
中,get '/resource/:id'
将正常工作。I just ran into the same issue. Since there was no answer here for how to do this without Passenger, I'm going to document the solution for Apache + CGI or FastCGI.
The trick is to rewrite
PATH_INFO
for Rack, and everything will fall into place:Set up
.htaccess
:In your Sinatra code, before anything else:
Now all URLs like
/subfolder/resource/123
will hit the correct route in the Sinatra app.In the above case
get '/resource/:id'
will work correctly, assuming the Sinatra app was put into/subfolder
.