Now I am pretty new to Sinatra/Ruby/Apache but have inherited a Sinatra application to depl开发者_高级运维oy.
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?
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
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
:RewriteEngine On RewriteRule ^(.*)$ sinatra_app.cgi [QSA,L,E=PATHINFO:/$1]
In your Sinatra code, before anything else:
ENV['PATH_INFO'] = ENV['REDIRECT_PATHINFO']
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
.
精彩评论