mod-rewrite - 从一个域代理/重写到另一个域的 lighttpd 配置

标签 mod-rewrite lighttpd mod-proxy

我需要在lighttpd上设置代理/重写!

我有 server1,它通过 http 2 不同的 Web 应用程序路径提供服务:

* http://server1/path1
* http://server1/path2

另外,我在 server1 前面有 lighttpd 服务器

我想在 lighttpd 上设置重写和/或代理,以便这 2 条路径中的每一条都用作不同域上的根路径:
* requests to http://server2.com/* are proxied/rewrited to http://server1/path1/*
* requests to http://server3.com/* are proxied/rewrited to http://server1/path2/*

重要的:
  • server2.com 和 server3.com 只能通过 http
  • 访问 server1
  • 重定向不是选项,server2.com 和 server3.com 的用户不应该知道实际的 Web 应用程序是从 server1 的不同路径提供的。

  • 是否可以?

    最佳答案

    多年来,lighttpd 开发人员都知道您的需求。

    根据版本的不同,它会通过变通方法或新功能来回答。

    Lighttpd 1.4

    错误跟踪器中解释了一种解决方法:bug #164

    $HTTP["url"] =~ "(^/path1/)" {   
      proxy.server  = ( "" => ("" => ( "host" => "127.0.0.1", "port" => 81 ))) 
    }
    
    $SERVER["socket"] == ":81" {   
      url.rewrite-once = ( "^/path1/(.*)$" => "/$1" )   
      proxy.server  = ( "" => ( "" => ( "host" => "server2.com", "port" => 80 ))) 
    }
    


    Lighttpd 1.5

    他们使用此命令( official documentation )添加了此功能:

    proxy-core.rewrite-request : rewrite request headers or request uri.

    $HTTP["url"] =~ "^/path1" {
      proxy-co...
    
      proxy-core.rewrite-request = (
        "_uri" => ( "^/path1/?(.*)" => "/$1" ),
        "Host" => ( ".*" => "server2.com" ),
      )
    }
    

    关于mod-rewrite - 从一个域代理/重写到另一个域的 lighttpd 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14536554/

    相关文章:

    c - lighttpd : Close its client socket by throwing error "Connection reset by peer"

    http - 用 lighttpd 重写 - 如何删除文件扩展名

    apache - Tomcat 子域关联

    apache - 使用 Apache 通过安全代理提供 3rd 方图像?

    Apache ProxyPass HTTPS 和带有 SNI 的远程服务器

    php - 从 URL 中删除 .php

    php - htaccess 出现问题(每个页面上都显示一个参数)

    .htaccess - 拒绝来自除一个域之外的所有域的推荐

    PHP 漂亮的 URL 结合了两个 mod_rewrite 规则?

    c - 如何静态编译lighttpd模块