What are your long-term experiences, using Go built-in server vs nginx

polaris · · 248 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi guys,</p> <p>For experienced people, compare and contrast using the go built-in (standard library) server for production, with nginx. Is Go good enough for any size production and has all the bells and whistles you need?</p> <p>I am particularly interested in logging as I would think maybe nginx has more logging than it does? (Just my impression since Go http server seems so simple).</p> <p>Of course Go server is definitely production-ready and very small and extremely easy to start using immediately. My impression is, if you have a Go server it takes less than 14 seconds to have an http server up. (Maybe another 45 to add a firewall rule if you&#39;re using that.)</p> <p>I&#39;m just wondering if people <em>keep</em> using it as they scale, or whether they eventually migrate away?</p> <p>Thanks for sharing your thoughts and experiences, including on any aspects I missed or got wrong!</p> <hr/>**评论:**<br/><br/>shovelpost: <pre><p>You are probably looking for this: <a href="https://blog.cloudflare.com/exposing-go-on-the-internet/">https://blog.cloudflare.com/exposing-go-on-the-internet/</a></p> <p>Even if you decide to migrate later, you&#39;ll still have a production ready in-app server.</p></pre>itsmontoya: <pre><p>We stopped using nginx proxy sometime after 1.4.2 and never looked back. </p></pre>titpetric: <pre><p>I still have things that are larger than a single server, so I need a reverse proxy of sorts. Having used many different ones in the past (pound, haproxy,...), I&#39;m very comfortable of having nginx to sit there, because it adds extended functionality (caching, LUA, redis,...). That&#39;s very useful for assets which aren&#39;t the Go service, but let&#39;s say several over 1TB of an image archive. To implement some of these things in Go isn&#39;t exactly what you want to do when starting up, and if you grow very fast, it&#39;s still better to take nginx and put it in front of a pool of Go services in a few hours, instead of developing and hardening the set of features which you need. There are of course Go attempts that aim as a nginx replacement, notably <a href="https://traefik.io/" rel="nofollow">traefik</a>. It still doesn&#39;t do caching, but then again, there are go-land solutions for that as well. Like this one, which was on the subreddit a few weeks ago: <a href="https://www.reddit.com/r/golang/comments/6wnxhc/a_multimaster_distributed_caching_layer_for/" rel="nofollow">multi master distributed caching layer for amazon s3</a>. I&#39;m sure it could be adapted to have a more general purpose within your app.</p></pre>SkaterDad: <pre><p>Have you tried <a href="https://caddyserver.com/" rel="nofollow">caddy</a> as a reverse proxy?</p> <p>I&#39;m currently considering it to replace <code>nginx</code> since it seems easier to setup and use (especially the automatic SSL). Probably isn&#39;t as fast as nginx, but would like to know your thoughts.</p></pre>sh41: <pre><p>I&#39;ve been hosting my personal site and some other sites via a simple Go program [1] (as opposed to something like nginx) for the last 1-2 years, and have not had any known issues as a result of that that would drive me away from it.</p> <p>[1] <a href="https://gist.github.com/d3b1c1c2215bf5b34190" rel="nofollow">https://gist.github.com/d3b1c1c2215bf5b34190</a> (and <a href="https://gist.github.com/bf19e90ca5cf502c7de2" rel="nofollow">https://gist.github.com/bf19e90ca5cf502c7de2</a> for HTTP-&gt;HTTPS redirection).</p></pre>phoenix_reborn86: <pre><p>14 seconds? ... That&#39;s <em>some</em> initialization logic you&#39;ve got there.</p></pre>Panniculus_Harpooner: <pre><p>I think he meant how long it takes to go from zero to coding a &#34;hello world&#34; server and launching it.</p></pre>phoenix_reborn86: <pre><p>That makes a lot more sense now. :P</p></pre>b4ux1t3: <pre><p>Honestly, regarding logging, I would use Go.</p> <p>Yes, you have to roll your own logs. Yes, Nginx has a pretty robust logging capability.</p> <p>But you get to control <em>exactly</em> what is logged in Go, because you get to wrote your own logging feature. And if you&#39;re building this site as a way to hone your skill, building a proper logger (or implementing a library for logging) is going to <em>serve</em> you better than just editing a configuration file. (Ha, see what I did there? I&#39;ll see myself out) </p></pre>paul2048: <pre><p>this isn&#39;t one VS the other. They have 2 very different roles.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

248 次点击  
加入收藏 微博
0 回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传