If I'm forced to run Go on Windows Server ...

xuanbao · · 956 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>After successfully migrating two Windows shops to FreeBSD, it&#39;s a tougher sell at my current place. I might have better success converting them to Go first, however, but I&#39;m not a Windows guy and know next to nothing about setting that server up. </p> <p>They run PHP for the main site now and just transferred everything over to a new server running the latest version. Are there some basic, relatively simple instructions for putting that together and, preferably, running Go&#39;s server simultaneously to serve out a test site? I know there are instructions on using nginx to proxy that on Windows but, to start out, it might be easier just to use Go.</p> <hr/>**评论:**<br/><br/>kardianos: <pre><p>Go runs the same way on Windows as it does on FreeBSD or Linux (aside from how syscalls work). To run a process in the background you must run it as a Windows service. I use <a href="https://github.com/kardianos/service" rel="nofollow">https://github.com/kardianos/service</a> which uses <a href="http://godoc.org/golang.org/x/sys/windows/svc" rel="nofollow">http://godoc.org/golang.org/x/sys/windows/svc</a> .</p> <p>I don&#39;t really understand your second paragraph, but it sounds like a Go question, not a windows question.</p></pre>forgotmyusername3xx: <pre><p>It&#39;s a Windows question. If I install Go on the Win server, how do I serve out pages from a Go server without interfering with the running PHP site on the same server. </p> <p>You may have partly answered the question with &#34;you must run it as a Windows service&#34; which I don&#39;t know anything about but it gives me something to Google for (though I found some on MSDN which are mind-bogglingly difficult to follow and understand).</p></pre>Arzh: <pre><p>What do you mean install Go? You only need to install go on your dev environment and build the exe. After that you will need to put the exe on the server and /maybe/ set up a service to handle it. I&#39;m not really following your problem.</p></pre>dhdfdh: <pre><p>He asked: how ... do ... you ... do ... that. He&#39;s not a Windows guy.</p></pre>Arzh: <pre><p>Fuck off, your bullshit won&#39;t help</p></pre>dhdfdh: <pre><p>Says the guy who can&#39;t answer the question.</p></pre>kardianos: <pre><p>For windows server, just the the provided link and keep it simple. Then to manage open up the services snap in (or look for the services node in Computer Management).</p> <p>To serve under the existing server, you could use FastCGI (if under IIS <a href="http://www.iis.net/downloads/microsoft/fastcgi-for-iis" rel="nofollow">http://www.iis.net/downloads/microsoft/fastcgi-for-iis</a> ) <a href="http://godoc.org/net/http/fcgi" rel="nofollow">http://godoc.org/net/http/fcgi</a> or you could serve on a different port and use the existing server as a reverse proxy (IIS URL Rewrite <a href="http://weblogs.asp.net/owscott/creating-a-reverse-proxy-with-url-rewrite-for-iis" rel="nofollow">http://weblogs.asp.net/owscott/creating-a-reverse-proxy-with-url-rewrite-for-iis</a> )</p></pre>soybean: <pre><p>You don&#39;t need to install go on your windows servers. You just need to install the windows binaries of your application. You could easily cross compile your application with a tool like goxc on unix machine.</p></pre>robertmeta: <pre><p>An easier way than touching the existing web server is just ask for another IP to be assigned to the box. Then you just fire it up as a windows service (make it properly respond to all service cues) and bind it to port 443 (or 80 if you are a monster) on $NEWIP. </p></pre>headzoo: <pre><p>Can&#39;t you run the go server and listen on a different port, like 8080?</p></pre>forgotmyusername3xx: <pre><p>Yes I can but the question is about how to set it up on a Windows server, not how to run it.</p></pre>headzoo: <pre><p>Your question is incredibly vague. You&#39;re getting confused responses because there&#39;s nothing to setup. You open a command line prompt and type <code>go nameofyourapp</code> and <em>poof</em> it&#39;s running. It&#39;s the same as running on a Go app on any other OS. If you build you Go app to listen on port 8080 it won&#39;t interfere with the PHP app. Then open a browser, type in the IP of the server along with port 8080 and you&#39;re done, e.g. <code>http://198.168.1.233:8080</code>.</p> <p>My hunch is you&#39;re confusing &#34;Windows server&#34; with &#34;IIS&#34;. <a href="https://en.wikipedia.org/wiki/Internet_Information_Services" rel="nofollow">IIS</a> is the Windows equivalent of Apache/Nginx. But you&#39;re not asking how to run a Go app through IIS. You&#39;re asking how to run it on Windows, and the answer is you run it the same way you would run it on FreeBSD.</p></pre>forgotmyusername3xx: <pre><p>I just went to the server and typed &#34;go myapp&#34; and got an error. Why didn&#39;t it work? </p> <p>Get my drift?</p> <p>I keep getting told I need to install Go as a &#34;service&#34;. Ok. The question I asked twice, now, is &#34;How do I do that?&#34; I asked for a simple, basic, instruction somewhere on what to do but, in typical reddit fashion, I get every response imaginable except an answer to the direct question.</p> <blockquote> <p>My hunch is you&#39;re confusing &#34;Windows server&#34; with &#34;IIS&#34;.</p> </blockquote> <p>I am not and specifically avoided mentioning it.</p> <blockquote> <p>you&#39;re not asking how to run a Go app through IIS.</p> </blockquote> <p>Exactly.</p> <blockquote> <p>the answer is you run it the same way you would run it on FreeBSD.</p> </blockquote> <p>No that is not the answer. </p> <p>My specific question I&#39;ll repeat here:</p> <blockquote> <p>Are there some basic, relatively simple instructions for putting that together and, preferably, running Go&#39;s server simultaneously to serve out a test site? </p> </blockquote> <p>Since we don&#39;t use a &#34;service&#34; to install and run Go on FreeBSD, you don&#39;t do things &#34;the same way&#34; on Windows and none of the directions I&#39;ve been pointed to, so far, do things the same way.</p></pre>Fwippy: <pre><p>&#34;An error&#34; Jeez, you&#39;re really dead-set on being as vague as possible, aren&#39;t you?</p> <p>I don&#39;t think you have the foggiest idea of what you want to accomplish, and you certainly aren&#39;t telling us.</p></pre>headzoo: <pre><p>You don&#39;t run Go as a service on Windows. Just get that out of your head for christ sakes. Here are the binary downloads <a href="https://golang.org/dl/" rel="nofollow">https://golang.org/dl/</a> Download the MSI. Click it. It installs Go. From there you can type <code>go</code> on the command line like any other OS. It&#39;s literally no different than downloading a .pkg or .deb or .rem, clicking it, and the app gets installed. It&#39;s easy enough that a 10 year old can do it.</p> <p>* Just like *nix based apps, you may have to add the go bin directory to your path after installing it.</p></pre>Arzh: <pre><p>What do you mean by &#39;set it up&#39; all you need is the exe. Are you trying to tie it to an IIS server or something?</p></pre>PrincessRailgun: <pre><p>Your webserver should handle it, like a proxy_pass to the go server on another port like you say in your OP. </p></pre>sanatgersappa: <pre><p>You might also want to check this out (Azure-specific, but still) - <a href="http://www.wadewegner.com/2014/12/4-simple-steps-to-run-go-language-in-azure-websites/" rel="nofollow">http://www.wadewegner.com/2014/12/4-simple-steps-to-run-go-language-in-azure-websites/</a></p></pre>forgotmyusername3xx: <pre><p>This may be the simplest. Thanks!</p></pre>jmking: <pre><p>If the site is currently working on PHP, why would you migrate that to Go? If a basic PHP stack is getting the job done, Go seems like overkill, no?</p> <p>Or is this for a separate application that needs to sit alongside the PHP site?</p></pre>forgotmyusername3xx: <pre><p>I&#39;m bringing it into the modern world and it&#39;s a fairly complex site with ecommerce, subscriptions, video subscriptions and so on. Currently it breaks and gets cracked on a regular basis. So a total rewrite by someone who knows what they&#39;re doing.</p> <p>And as someone who knows what they&#39;re doing, I won&#39;t use PHP (or Windows for that matter).</p></pre>jmking: <pre><p>If they&#39;ve given you license for a complete re-build, and this app is the only thing on the server, I don&#39;t see why they&#39;d insist on keeping Windows.</p></pre>forgotmyusername3xx: <pre><p>You haven&#39;t been in this business very long, have you? :)</p> <p>Get this. This site was last coded 10 years ago. It uses deprecated PHP. Most of the pages don&#39;t have a doctype, use tables for layout, transfer credit card information in plain text ... and they don&#39;t see anything wrong with any of that. </p> <p>Now, I&#39;m a high priced developer. I was hired to do this three months ago. Want to know what I&#39;ve accomplished for them? Zero. Nada. Zilch. </p> <p>What do I do all day? Work on other client&#39;s web sites who are also paying me at the same time. I&#39;m practically doubling my salary. Want to know the last time I talked to the guy who hired me? A week and a half ago. Haven&#39;t seen him at all.</p> <p>This is the type of place I&#39;m doing work for and you can imagine the mindset.</p> <p>Not that there&#39;s anything wrong with that.</p></pre>jmking: <pre><p>I... don&#39;t... understand how that answers anything?</p> <p>They&#39;re letting you do whatever you want, EXCEPT choose the server tech? That doesn&#39;t make any sense...</p> <p>Unless you&#39;re implying that a server move would require the client to do something, and they are very unlikley to ever get something like that done/approved?</p></pre>brokedown: <pre><p>Linux guy here. I&#39;ve got an app that I needed cgo for and wanted it to work on Windows, and spent entirely too long getting that to work (note: 32 bit go and 32 bit mingw finally got a result).</p> <p>If you stay away from cgo (and packages that secretly use it), you shouldn&#39;t see much difference compared to unix.</p></pre>thomasfr: <pre><p>Iirc mingw is what the go docs suggests for building go and maybe also for using cgo.. Even cross compiling from debian with mingw was relatively easy compared with most other build systems i have used.</p></pre>brokedown: <pre><p>mingw-w64 is what the docs suggest, and I was never able to get a functional system with it. Moving to 32 bit Go and 32 bit mingw got me a working toolchain.</p></pre>thomasfr: <pre><p>Aha, I never had any issues with any of them. Let&#39;s blame magic :)</p></pre>forgotmyusername3xx: <pre><p>I didn&#39;t need to hear that. Actually, that may be my &#34;out&#34; cause the apps I&#39;ll be creating will need that, which will be my &#34;in&#34; to switching them away from Windows. I&#39;m getting good at that :)</p></pre>brokedown: <pre><p>Well if nothing else I gave you the ingredients that made it mostly work for me.</p></pre>iamedwards: <pre><p>I&#39;ve had luck with cgo as long as you compile on the native environment.</p></pre>PM_ME_YOUR_VIMRC: <pre><p>It would probably be best to compile it to node.js as it has better windows support.</p></pre>dongdongler: <pre><p>Your options are: * Run your Go app as a Windows service. Serve directly or via reverse proxy like the IIS ARR module * Run your Go app behind IIS using the httpPlatformHandler</p> <p>Either way, you just need to build the executable and decide how to run it. I write Go apps for *nix and Windows and the easiest path is using FastCGI. Once you get in to daemons/services platform differences get gross.</p> <p>PS it is irresponsible to migrate to {favorite stack} when {existing stack} is serving business needs just fine. We&#39;re here to provide value, and on good days scratch our own itches.</p></pre>

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

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