dongyulan6251 2014-07-05 15:07
浏览 187

Go Web App:如何从Golang将PHP脚本路由到PHP-FPM

I have one main web site and numerous small web sites. I'm currently using Nginx & PHP for all of this. My plan is to do away with both and build a single web app in Go that will serve everything, which will hopefully reduce load and memory (especially since some of the pages are very computationally heavy.)

My issue is that it would be a serious waste of time for me to try to port things like rarely used PHPBB forums to Go. So I'd like to have the main web site all served from the Go web app, but some of the other sites can remain as PHP.

My question is: can I use the Go web app to route requests for PHP scripts to PHP-FPM?

I would like it so that I can do away with Nginx, the web app will handle all of the incoming traffic and serve the main site directly from its own code, but for less important sites that are still in PHP these can be served by the Go app routing these requests to PHP-FPM (along with all the full request info including cookies, POST vars, etc.)

Any ideas?

  • 写回答

3条回答 默认 最新

  • download2565 2014-07-05 16:28
    关注

    To redirect to another url you can use httputil.HostReverseProxy

        origin := "http://php.website.com"
        originUrl, err := url.Parse(origin)
        if err != nil {
            log.Fatal(err)
        }
    
        proxy := httputil.NewSingleHostReverseProxy(originUrl)
        prev := proxy.Director
    
        proxy.Director = func(req *http.Request) {
            prev(req)
            req.Host = originUrl.Host
        }
    
        http.HandleFunc("/php", proxy.ServeHTTP)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型