douchao1957 2018-07-20 23:48
浏览 223

是否可以在内部(专用)IIS服务器上运行Golang REST Web应用程序?

I would like to create a web service with GoLang that runs either on IIS (7, 8 or 10) or under Tomcat 7.0. We have multiple environments, each with multiple servers, all being Windows 2008 R2, 2012 or 2016. All servers are private (10.x). My goal is to add some REST services to a COTS product that uses both IIS and Tomcat. I'd prefer to avoid gluing nginx or something else onto either server at the risk of impairing the COTS product or having their tech support people not answer the phone. Again .. the servers are only accessible via corporate VPN and are not public internet-facing.

Which server would offer the easiest path to get something working -- Tomcat or IIS?

  • 写回答

1条回答 默认 最新

  • dongrong8972 2018-07-21 16:53
    关注

    That's not really about Go, but still there exist at least two solutions I can think of:

    • Reverse proxying of HTTP requests.

      1. Write a plain Go server serving requests via HTTP.

        Maybe turn it into a proper Windows service using golang.org/x/sys/windows/svc.

      2. Deploy it.

        If it's to be hosted on the same machine which runs IIS, then it's fine to make it listen on localhost only. Note that it will need a dedicated TCP port to listen on, and you'll need to make it possible for your server to be somehow configurable in this regard.

      3. Set up reverse proxying in your IIS so that it forwards requests coming to whatever (part of an) URL you want to the Go server.
    • Use FastCGI.

      Go supports serving requests over the FastCGI protocol by means of its standard library, and IIS suports FastCGI workers.

      So it's possible to (re-)write your Go server to use FastCGI instead of HTTP and then hook it into IIS via this protocol.

    The pros and cons of these solutions—as I view them—are:

    • Serving over plain HTTP is more familiar to a developer and makes the server more "portable"—in the sense it will be easier to change its deployment scheme if/when you'll need it. Right to making it available to the Internet directly.

      Conversely, with FastCGI, you'll always need a FastCGI host as a "middleware".

    • There were rumors that HTTP code is more fine-tuned in terms of performance than that of FastCGI.

      Still, this only will be of concern for reasonably hard-core loads.

    • One possible upside of FastCGI over HTTP is that it can be served over pipes rather than TCP. For instance, you might get it served over named pipes as it's supported by IIS's FastCGI module and there exists 3rd-party packages for Go implementing support for them (even including one from Microsoft®).

      The upside of this is that pipes are beleived to incur lesser overhead for data transfer (basically it's just shoveling bytes between in-kernel buffers belonging to two processes instead of pushing them through the whole TCP/IP stack), and using pipes frees you from the need of dedicating a TCP port to the Go server.

      Still, I have no personal experience with this kind of setup and its performance trade-offs.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)