大网数据广告活动
服务器运维问答

Proxy URL to different port via Lighttpd

· 52CE 我爱测

I cannot seem to proxy a URL to another port on same hostname. I have user interface (Angular 5) running on somehost:8080 and the rest of the web application on somehost.com (port 80). I'd like to proxy http://somehost.com/xxx to…

问题原文

原帖链接 · Michael Niño · CC BY-SA 3.0

I cannot seem to proxy a URL to another port on same hostname. I have user interface (Angular 5) running on somehost:8080 and the rest of the web application on somehost.com (port 80). I'd like to proxy http://somehost.com/xxx to http://somehost.com:8080. Not sure if my configuration is correct or in the right place.

$HTTP["host"] =~ "somehost\.com$" {

        $HTTP["url"] =~ "(^/xxx/)" {
          proxy.server  = ( "" => ("" => ( "host" => "somehost.com", "port" => 8080 )))
        }

        url.rewrite-if-not-file = (
                "^/(.*)" => "/index.php/$1",
        )


}

已采纳解答

原帖链接 · Luca Gibelli · CC BY-SA 3.0

From your question it looks like you want to serve http://somehost.com/xxx/file from http://somehost.com:8080/file. In that case your config is wrong, because it is trying to serve http://somehost.com:8080/xxx/file instead. You need to add a url.rewrite-once:

  url.rewrite-once = ( "^/xxx/(.*)$" => "/$1" )
  proxy.server  = ( "" => ( # proxy all file extensions / prefixes
    "" => # optional label to identify requests in logs
      ( "host" => "somehost",
        "port" => 8080
      )
    )
  )

Depending on your version of lighttpd, you might or might not be able to call url.rewrite-once from within a $HTTP["url"] match.

Also make sure that you have loaded the mod_proxy and mod_rewrite modules with:

server.modules += ( "mod_proxy" )
server.modules += ("mod_rewrite")

More info on proxy.server: https://redmine.lighttpd.net/projects/1/wiki/Docs_ModProxy More info on url.rewrite-once: https://redmine.lighttpd.net/projects/1/wiki/docs_modrewrite#urlrewrite-repeat

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-04-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。