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条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?