{"id":13776085,"url":"https://github.com/waterlink/rack-reverse-proxy","last_synced_at":"2025-05-16T02:07:22.108Z","repository":{"id":56890220,"uuid":"38207934","full_name":"waterlink/rack-reverse-proxy","owner":"waterlink","description":"A Reverse Proxy for Rack","archived":false,"fork":false,"pushed_at":"2024-06-28T10:58:00.000Z","size":206,"stargazers_count":194,"open_issues_count":30,"forks_count":55,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-09T03:34:36.070Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/waterlink.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-28T17:39:37.000Z","updated_at":"2025-01-31T10:32:56.000Z","dependencies_parsed_at":"2024-08-03T17:21:37.073Z","dependency_job_id":null,"html_url":"https://github.com/waterlink/rack-reverse-proxy","commit_stats":{"total_commits":210,"total_committers":33,"mean_commits":6.363636363636363,"dds":0.7238095238095238,"last_synced_commit":"a4f28a6fe7028761fb014dce7fed4bb5a33503e8"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Frack-reverse-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Frack-reverse-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Frack-reverse-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waterlink%2Frack-reverse-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waterlink","download_url":"https://codeload.github.com/waterlink/rack-reverse-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453652,"owners_count":22073617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T17:01:59.979Z","updated_at":"2025-05-16T02:07:22.080Z","avatar_url":"https://github.com/waterlink.png","language":"Ruby","funding_links":[],"categories":["\u003ca id=\"01e6651181d405ecdcd92a452989e7e0\"\u003e\u003c/a\u003e工具","Middlewares"],"sub_categories":["\u003ca id=\"e9f97504fbd14c8bb4154bd0680e9e62\"\u003e\u003c/a\u003e反向代理"],"readme":"# A Reverse Proxy for Rack\n[![TravisCI](https://secure.travis-ci.org/waterlink/rack-reverse-proxy.svg \"Build Status\")](http://travis-ci.org/waterlink/rack-reverse-proxy \"Build Status\")\n\nThis is a simple reverse proxy for Rack that pretty heavily rips off Rack Forwarder. It is not meant for production systems (although it may work), as the webserver fronting your app is generally much better at this sort of thing.\n\n## Installation\nThe gem is available on rubygems.  Assuming you have a recent version of Rubygems you should just be able to install it via:\n\n```\ngem install rack-reverse-proxy\n```\n\nFor your Gemfile use:\n\n```ruby\ngem \"rack-reverse-proxy\", require: \"rack/reverse_proxy\"\n```\n\n## Usage\n\n`Rack::ReverseProxy` should ideally be the very first middleware in your\nstack. In a typical use case it is being used to proxy an entirely\ndifferent website through your application, so it's unlikely that you will want\nany other middleware to modify the requests or responses. The examples below\nreflect this.\n\n\n### Generic Rack app example\n\n```ruby\nrequire 'rack/reverse_proxy'\n\nuse Rack::ReverseProxy do\n  # Set :preserve_host to true globally (default is true already)\n  reverse_proxy_options preserve_host: true\n\n  # Forward the path /test* to http://example.com/test*\n  reverse_proxy '/test', 'http://example.com/'\n\n  # Forward the path /foo/* to http://example.com/bar/*\n  reverse_proxy /^\\/foo(\\/.*)$/, 'http://example.com/bar$1', username: 'name', password: 'basic_auth_secret'\nend\n\napp = proc do |env|\n  [ 200, {'Content-Type' =\u003e 'text/plain'}, [\"b\"] ]\nend\nrun app\n```\n\n### Ruby on Rails app example\n\nThis example use `config.middleware.insert(0` to ensure that\n`Rack::ReverseProxy` is first in the stack. It is possible that\nother code in your app (usually in application.rb, development.rb, or production.rb)\nwill take over this position in the stack. To ensure\nthat this is not the case, view the stack by running `rails middleware`. You should see\n`Rack::ReverseProxy` at the top. Note that\nthe middleware stack will likely differ slightly in each environment. All that said, it's a pretty\nsafe bet to put the below code into application.rb.\n\n```ruby\n# config/application.rb\nconfig.middleware.insert(0, Rack::ReverseProxy) do\n  reverse_proxy_options preserve_host: true\n  reverse_proxy '/wiki', 'http://wiki.example.com/'\nend\n```\n\n### Rules\n\nAs seen in the Rack example above, `reverse_proxy` can be invoked multiple times with\ndifferent rules, which will be commulatively added.\n\nRules can be a regex or a string. If a regex is used, you can use the subcaptures in your forwarding url by denoting them with a `$`.\n\nRight now if more than one rule matches any given route, it throws an exception for an ambiguous match.  This will probably change later. If no match is found, the call is forwarded to your application.\n\n\n### Options\n\n`reverse_proxy_options` sets global options for all reverse proxies. Available options are:\n\n* `:preserve_host` Set to false to omit Host headers\n* `:username` username for basic auth\n* `:password` password for basic auth\n* `:matching` is a global only option, if set to :first the first matched url will be requested (no ambigous error). Default: :all.\n* `:timeout` seconds to timout the requests\n* `:force_ssl` redirects to ssl version, if not already using it (requires `:replace_response_host`). Default: false.\n* `:verify_mode` the `OpenSSL::SSL` verify mode passed to Net::HTTP. Default: `OpenSSL::SSL::VERIFY_PEER`.\n* `:x_forwarded_headers` sets up proper `X-Forwarded-*` headers. Default: true.\n* `:stripped_headers` Array of headers that should be stripped before forwarding reqeust. Default: nil.\n  e.g. `stripped_headers: [\"Accept-Encoding\", \"Foo-Bar\"]`\n\nIf `reverse_proxy_options` is invoked multiple times, the invocations will have a commulative effect,\nonly overwritting the values which they specify. Example of how this could be useful:\n\n```ruby\nconfig.middleware.insert(0, Rack::ReverseProxy) do\n  reverse_proxy_options preserve_host: false\n  if Rails.env.production? or Rails.env.staging?\n    reverse_proxy_options force_ssl: true, replace_response_host: true\n  end\n  reverse_proxy /^\\/blog(\\/?.*)$/, 'http://blog.example.com/blog$1'\nend\n```\n\n## Note on Patches/Pull Requests\n* Fork the project.\n* Make your feature addition or bug fix.\n* Add tests for it. This is important so I don't break it in a\n  future version unintentionally.\n* Commit, do not mess with rakefile, version, or history.\n  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)\n* Send me a pull request. Bonus points for topic branches.\n\n## Contributors\n\n- Jon Swope, creator\n- Oleksii Fedorov, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaterlink%2Frack-reverse-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaterlink%2Frack-reverse-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaterlink%2Frack-reverse-proxy/lists"}