重写规则以从 Rails 服务器的 URL 中隐藏端口? [英] Rewrite rule to hide port from URL of Rails server?
问题描述
我有一个运行在 URLhttp://example.com:1234"上的 rails 服务器我想将此应用程序的 URL 以http://example.com/myapp"的形式提供给用户,以便 Apache(或 Rack 或任何您建议有效的东西)可以将对/myapp"的请求重定向到该端口的 3333域.
I have a rails server running on URL "http://example.com:1234" I want to provide the URL of this application to an user as "http://example.com/myapp" so that Apache (or Rack or whatever you suggest that works) can redirect request for "/myapp" to port 3333 of that domain.
推荐答案
看看设置一个 apache 下的反向代理.
Apache 在 example.com 上侦听端口 80,将反向代理到端口 1234.然后请求 http://example.com/myapp 将在内部代理到 http://example.com:1234/myapp(或者您如何设置 ProxyPass 目标).
Apache, listening to port 80 on example.com, would reverse proxy to port 1234. Then requests for http://example.com/myapp would be internally proxied to http://example.com:1234/myapp (or however you setup your ProxyPass target).
如果您无权访问服务器配置,您可以使用 mod_rewrite 的代理标志并在 .htaccess 文件中设置一些规则.类似的东西:
If you don't have access to server config, you can use mod_rewrite's Proxy flag and setup some rules inside an .htaccess file. Something along the lines of:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^myapp(.*) http://example.com:1234/$1 [P,L]
这篇关于重写规则以从 Rails 服务器的 URL 中隐藏端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!