【问题标题】:Apache: Rewrite then ProxyApache:重写然后代理
【发布时间】:2016-06-14 16:21:17
【问题描述】:

所以,我有两台服务器,我们称它们为 nice#server 和 a#another#server

nice#server 是客户端将与之交谈的对象,它正在运行 Apache2,为简单的服务执行基本的反向代理,a#another#server 在 port 上托管一个专有的应用程序服务器。我需要在它们通过之前完全重写两个 url,但只需将一个文件夹添加到所有其他 URL。

下面的一些例子:

User Requests: nice#server/
Apache requests a#another#server:8080/appname

User Requests: nice#server/css#css
Apache requests a#another#server:8080/appname/css#css

User Requests: nice#server/a
Apache requests a#another#server:8080/appname/command1?name=option1

User Requests: nice#server/b
Apache requests a#another#server:8080/appname/app2?name=option2

我已经对此进行了很多谷歌搜索和测试,但似乎无法使其正常工作,抱歉我没有保留我尝试过的链接!!!我现在已经剥离了 vHost 文件。

<VirtualHost *:80>
  ServerName              service#domain#com
  ErrorLog                ${APACHE_LOG_DIR}/service-domain-com-error.log
  LogLevel                warn
  CustomLog               ${APACHE_LOG_DIR}/service-domain-com-access.log combined
  ProxyPreserveHost       On
  ProxyRequests           off
  ProxyPass               / a#another#server:8080/
  ProxyPassReverse        / a#another#server:8080/
</VirtualHost>

提前感谢您提供有关如何执行此操作的任何指导。

【问题讨论】:

    标签: apache mod-rewrite virtualhost mod-proxy


    【解决方案1】:

    我通过一些试验和错误设法解决了这个问题。在这里发布解决方案,以防其他人遇到问题。

    工作配置文件

    <VirtualHost *:80>
        ServerName              service.domain.com
    
        ErrorLog                ${APACHE_LOG_DIR}/internal-fqdn-error.log
        LogLevel                warn
        CustomLog               ${APACHE_LOG_DIR}/internal-fqdn-access.log combined
    
        RewriteEngine           On
        RewriteRule             ^/a$ /appname/command1?name=option1 [PT]
    
        ProxyPreserveHost       On
        ProxyRequests           off
        ProxyPass               /       http://a.another.server:8080/
        ProxyPassReverse        /       http://a.another.server:8080/
    </VirtualHost>
    

    【讨论】:

      猜你喜欢
      • 2012-08-09
      • 2014-03-17
      • 2017-03-16
      • 1970-01-01
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 2013-04-23
      • 2019-07-01
      相关资源
      最近更新 更多