doubi7346 2015-10-14 13:32
浏览 40
已采纳

Go(lang)应用程序:Nginx反向代理VS Nginx主机

I have already read some of the questions about go and nginx but I didn't find any answer to my one.

I think (i'm not an expert) that using nginx as a reverse proxy in front of a net/http go server is different as directly hosting your go application with nginx.
Shout at me if I'm wrong, ok?

The question came to me because I need to develop an application (possibly with go, just to learn something new) and have total control on the webserver, especially on the number of workers it uses to answer requests.

So, here come the questions:

  1. Is it possible to directly host a go app on nginx, or is it nginx that only serves static files (if the answer is "NO", then the second question doesn't make much sense)?

  2. What are the key differences between the two approaches above, precisely, does the different approaches affects the configuration someway?

  3. I am scared about telling nginx: "Ok, use 8 workers, please" and telling nothing to go's internal webserver... What would happen?

Thank you so much in advance

  • 写回答

2条回答 默认 最新

  • douwen5924 2015-10-14 13:59
    关注

    Is it possible to directly host a go app on nginx

    Nginx can communicate with its backend (your app) through various different mechanisms. Some of them are:

    • Via CGI/FastCGI (process multiplexing)
    • Via HTTP (reverse proxying)
    • Serving static files which your app produced

    does the different approaches affects the configuration someway?

    Yes, each case is very different.

    Ok, use 8 workers, please

    That would suggest FastCGI, which I believe is what you mean when you say "directly hosting an application on nginx".

    telling nothing to go's internal webserver... What would happen?

    Each Go FastCGI process would spawn a lot of goroutines, which are multiplexed to software threads, which are multiplexed to hardware threads, which are multiplexed to CPU cores.

    Go's net/http server is good enough for a production environment, you don't necessarily need nginx unless you want to use some nginx-specific feature. There are only so many use cases where a FastCGI setup makes sense. You just add overhead, basically.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度