$SERVER["socket"] == ":8082" {
server.name = "localhost"
#server.document-root = server_root + "/dist"
server.document-root = "/var/www/dist" #前端页面的静态文件目录,相当于nginx的root alias
index-file.names += (
"index.xhtml", "index.html", "index.htm", "default.htm", "index.php" #相当于nginx的index 指令
)
如果需要监听多个端口加入以下配置
$SERVER["socket"] == ":8083" {
........
proxy.server = ( "/api" => #相对于nginx的 location /api
((
"host" => "127.0.0.1",
"port" => 8080
))
)
以上配置表示所有的 /api请求全都发往后端 127.0.0.1:8080端口,有时候前端静态文件里面会统一加个/api的路径请求到后端,如果后端没有 /api的接口会导致报404错误,这时候需要像nginx的功能配置 location /api {
proxy_pass http://127.0.0.1:8080/; 最后加个反斜杠 /,表示api的请求不带到后端url里面
lighttpd加入以下配置接口实现:
proxy.header = (
"map-urlpath" => (
"/api" => ""
)
)
参考官方文档:Mod proxy - Lighttpd - lighty labshttps://redmine.lighttpd.net/projects/lighttpd/wiki/Mod_proxy
完整的配置文件:
$SERVER["socket"] == ":8090" {
server.name = "localhost"
#server.document-root = server_root + "/dist"
server.document-root = "/var/www/dist"
index-file.names += (
"index.xhtml", "index.html", "index.htm", "default.htm", "index.php"
)
url.access-deny = ( "~", ".inc")
proxy.server = ( "/api" =>
((
"host" => "127.0.0.1",
"port" => 8080
))
)
proxy.header = (
"map-urlpath" => (
"/api" => ""
)
)
}