apache_conf 一个示例config.ru文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache_conf 一个示例config.ru文件相关的知识,希望对你有一定的参考价值。
# 301 rewrite!
require 'rack/rewrite'
use Rack::Rewrite do
r301 %r{.*}, 'http://somedomain.com$&', :if => Proc.new {|rack_env|
rack_env['SERVER_NAME'] != 'somedomain.com'
}
end
# Attribution goes to https://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/try_static.rb
# License can be found here https://github.com/rack/rack-contrib/blob/master/COPYING
module Rack
class TryStatic
def initialize(app, options)
@app = app
@try = ['', *options.delete(:try)]
@static = ::Rack::Static.new(
lambda { [404, {}, []] },
options)
end
def call(env)
orig_path = env['PATH_INFO']
found = nil
@try.each do |path|
resp = @static.call(env.merge!({'PATH_INFO' => orig_path + path}))
break if 404 != resp[0] && found = resp
end
found or @app.call(env.merge!('PATH_INFO' => orig_path))
end
end
end
# Set up static serving
use Rack::TryStatic, :root => "_site", :urls => %w[/], :try => ['.html', 'index.html', '/index.html']
# Serve the 404 error page
error_file = '_site/404.html'
run lambda { |env|
[404, {
'Last-Modified' => File.mtime(error_file).httpdate,
'Content-Type' => 'text/html',
'Content-Length' => File.size(error_file)
},
File.read(error_file) ]
}
以上是关于apache_conf 一个示例config.ru文件的主要内容,如果未能解决你的问题,请参考以下文章
Gem 不会通过 config.ru 加载
ruby 如果你想在heroku上为你的中间人应用程序添加基本身份验证,这是一个添加到middleman的config.ru文件的片段
apache_conf 配置示例1
apache_conf 301重定向示例
apache_conf 示例RESTful脚本
apache_conf Htaccess缓存示例