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)
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料