I'm trying to figure out how to come up with a basic web page on a shared web host with Go.

blov · · 566 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I use Namecheap (their cheapest plan, or close to it), and they recently tweeted me back letting me know that this can be done. So when I Google this, the examples I see have you coding up a server... well, NC already provides a server for me, so this would not need to be written, is that right? I hope I don&#39;t have anything too mixed up and I&#39;m sorry if I do.<br/> I would know what to do if I wanted to use PHP. Somehow I don&#39;t think it&#39;s as easy with Go, if you&#39;re just renting on a cheap web host. </p> <hr/>**评论:**<br/><br/>pkalchev: <pre><p>Hey thinkvitamin,</p> <p><em>Warning - I&#39;m a junior sysadmin who tries programming sometimes - there is a big chance I&#39;m doing it wrong! :P</em></p> <p>For shared hosting you need to use golang as a CGI. For example something like this worked on the shared hosting I&#39;ve tested: <a href="https://play.golang.org/p/Byk3FT1XBf" rel="nofollow">https://play.golang.org/p/Byk3FT1XBf</a></p> <p>Compile it, name it for example index.cgi and create .htaccess with something like:</p> <pre><code>Options ExecCGI SymLinksIfOwnerMatch AddHandler cgi-script .cgi RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.cgi?path=$1 [NC,L,QSA] </code></pre> <p>Hope it helps. That&#39;s the best I&#39;ve come with for the moment.</p></pre>hobbified: <pre><p>That should work, yes, but bear in mind that it&#39;s a terrible idea performance-wise, and that you won&#39;t be able to use pretty much any of the web libraries/frameworks out there (including the built-in ones), because they&#39;re all pretty tightly married to the idea of an HTTP server; there isn&#39;t a WSGI/Rack/Plack-like abstraction layer that would support running the same code in net/http, CGI, FastCGI, testing, etc. environments.</p></pre>pkalchev: <pre><p>About the performance - absolutely! But since he asked about shared hosting this is the only realistic way to run it (at least from what I&#39;ve seen so far). About the frameworks - for my testing I&#39;ve used github.com/gorilla/mux and it worked (at least for the simple things I did..) - not sure if it will do for something more complex. Basically I created a simple API that can accept json with user information and write it in MySQL, get that information from mysql and delete an entry. </p></pre>codeonline: <pre><p>Give digital ocean a try, you can get an small virtual machine for $5 per month - and you only pay by the hour (less than one cent per hour). They have prepacked &#39;onclick&#39; images that you can create a machine from. Try the LAMP stack to start if you&#39;re more familiar with that and then try GO once you&#39;re comfortable with the accessing the vm and installing software etc. any time you do anything wrong, just destroy it and start again. There are often coupons available for new users too <a href="https://www.retailmenot.com/view/digitalocean.com" rel="nofollow">https://www.retailmenot.com/view/digitalocean.com</a></p></pre>earthboundkid: <pre><p>I&#39;m not familiar with Namecheap, but on my old shared host (before I switched to VPS), when you wanted to start a web app like Ruby on Rails or Django, they would assign you a random port number, and then direct traffic to that port. I imagine Namecheap works the same way. So, instead of listening on port 80 (standard http port) or 443 (standard https port) or even :3000 or :8000 (default ports for Ruby on Rails and Django respectively), you&#39;d be on port :388732 or whatever. In Go, just pass that port number into <a href="https://godoc.org/net/http#ListenAndServe" rel="nofollow">http.ListenAndServe</a> when you run your program.</p></pre>earthboundkid: <pre><p>Hmm, a quick look at their website makes it seem like you don&#39;t get CGI or port sharing with their cheapest level plan. You may want to go with someone more flexible like a VPS or WebFaction because their higher priced plans are basically a rip off.</p></pre>pkalchev: <pre><p>That is an option (if they allow it), but how will you be sure you app will restart it&#39;s server if it fails/get&#39;s killed... or just something happens to it :D If your provider uses cPanel/WHM you could ask for them to add your app to chkservd (it&#39;s integrated with cPanel/WHM) to check if your app is running and if not - restart it, but I highly doubt that they will agree.</p></pre>1Gijs: <pre><p>Shared hosting plans only support (the most common) interpreted languages: php and python. Golang is a compiled language.</p></pre>thepciet: <pre><p>I&#39;m working on a local business that builds off-the-shelf Internet web delivery computers (e.g. <a href="https://newegg.com" rel="nofollow">https://newegg.com</a>) for about $500 in parts and hope that home AGPL Linux network computers move with demand I make with neat open source Go HTTP/HTML web applications.</p> <p>I use <a href="http://squarespace.com" rel="nofollow">http://squarespace.com</a> for Internet websites.</p> <p>[edit] I&#39;m just saying you are reinventing the wheel by making up a web server on some virtual computer somewhere.</p></pre>

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

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