<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't have anything too mixed up and I'm sorry if I do.<br/>
I would know what to do if I wanted to use PHP. Somehow I don't think it's as easy with Go, if you're just renting on a cheap web host. </p>
<hr/>**评论:**<br/><br/>pkalchev: <pre><p>Hey thinkvitamin,</p>
<p><em>Warning - I'm a junior sysadmin who tries programming sometimes - there is a big chance I'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'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's the best I've come with for the moment.</p></pre>hobbified: <pre><p>That should work, yes, but bear in mind that it's a terrible idea performance-wise, and that you won't be able to use pretty much any of the web libraries/frameworks out there (including the built-in ones), because they're all pretty tightly married to the idea of an HTTP server; there isn'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've seen so far). About the frameworks - for my testing I'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 'onclick' images that you can create a machine from. Try the LAMP stack to start if you're more familiar with that and then try GO once you'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'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'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'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's server if it fails/get'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'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'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'm just saying you are reinventing the wheel by making up a web server on some virtual computer somewhere.</p></pre>
I'm trying to figure out how to come up with a basic web page on a shared web host with Go.
blov · · 566 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传