十月
24

曹维远发Email给我提到这问题,可能其他人也会碰到这个问题,因此将我的回复发布在Blog中。

Caiwangqin, 你好,

我是曹维远,网名cvu,在uuzone上我们曾经互相加过好友。

初次交流,本来想说些仰慕的话,大家都忙,略过。

写信给你的直接目的是问一个rails的问题,我想让browser可以访问到我的一个硬盘目录里的图片,而这个目录不在public下面。

IIS管这个叫Virtual Directory, Apache叫Alias.

我查了rails的各类文档,routes.rb是最接近的,但是好像解决不了我的问题。

又有apache+mongrel的方案,我按照mongrel网站上的介绍,和冰狗的翻译,配置了httpd.conf如下

<VirtualHost *>
    ServerName typo
    ProxyPass / http://localhost:3002/
    ProxyPassReverse / http://localhost:3002
    ProxyPass /images !
    ProxyPass /stylesheets !
    ProxyPass /icons !
    #continue with other static files that should be served by apache

    Alias /images ${path}/rails_apps/typo-2.6.0/public/images
    Alias /stylesheets ${path}/rails_apps/typo-2.6.0/public/stylesheets
    Alias /icons ${path}/apache/icons
    #continue with aliases for static content

</VirtualHost>

但还是不行,不知道你有没有这方面经验。

谢谢!

我也曾想过同样的问题,好像通过Rails的routes.rb是不可以引用外部路径的,routes.rb是Rails内部的Rewrite规则。但可以通过将RoR应用配置成一个别名,然后将外部路径配置成另外的别名,即可在Rails Application中使用”/images/example.jpg”的方式引用外部路径了。提供参考(以下用Lighttpd示范,Apache配制类似):

server.document-root = “C:/lighttpd/htdocs/”

alias.url = (

“/images/” => “${path}/rails_apps/typo-2.6.0/public/images”,

“/stylesheets/” => “${path}/rails_apps/typo-2.6.0/public/stylesheets”,

“/icons/” => “${path}/apache/icons”

)

$HTTP[”url”] =~ “^/typo/” {

server.document-root = “e:/work/ror/typo/public”
server.error-handler-404 = “/dispatch.scgi”
server.indexfiles = ( “dispatch.fcgi” )
scgi.debug=0
scgi.server = ( “dispatch.scgi” => ((
“host” => “127.0.0.1″,
“port” => 9999,
“check-local” => “disable”,
“disable-time”=>0
)) )
}

希望能够有所帮助。

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg

Tags:

3 Responses

Leave a Response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>