我在 Apache 的 httpd.conf 中有一个反向代理设置:
ProxyPass "/endpoint" "https://someurl.com/endpoint"
ProxyPassReverse "/endpoint" "https://someurl.com/endpoint"
我需要在 Lighttpd 中复制它。我正在运行一个 JS 应用程序,它调用 localhost:8080/endpoint
来检索一些数据。我想设置一个代理以总是将/endpoint
重定向到https://someurl.com/endpoint
。
在我的 lighttpd.conf 中,我有以下设置:
server.modules = ("mod_proxy")
$HTTP["url"] =~ "^.*endpoint" {
proxy.server = ( "" => (( "host" => "https://someurl.com/endpoint" ) ) )
}
基于 this SO answer . 我也试过:
server.modules = ("mod_proxy")
proxy.server = ( "/endpoint" => (( "host" => "https://someurl.com/endpoint" )))
基于lighttpd docs .
在这两种情况下,我仍在点击 localhost:8080/endpoint
,这会导致 404 错误。如何正确设置代理?
最佳答案
在 lighttpd 1.4.46 及更高版本中,您可以使用 proxy.header
。看
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModProxy
server.modules = ("mod_proxy")
$HTTP["url"] == "/endpoint" {
proxy.server = ( "" => (( "host" => "someurl.com" )))
proxy.header = ( "map-host-request" => ( "-" => "someurl.com"),
"map-host-response" => ("-" => "-"))
}
关于reverse-proxy - Lighttpd反向代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48794514/