lighttpd实现nginx代理api接口到后端时取消api前缀proxy_pass http://127.0.0.1:8080/

$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 labsicon-default.png?t=MBR7https://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"  => ""
       )
       )

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值