http://www.vincepergolizzi.com/How-to-deploy-your-first-Go-web-app
Would appreciate some feedback on this, I'm quite new to Go and a lot of the stuff I wrote about so feel free to correct me or provide some suggestions on how to make the guide better.
评论:
1Gijs:
v89_cs:If you want to keep it simple, why add the nginx webserver ? Add the reason(s) why you think its good to do.
Also, I think by default a Digital Ocean Ubuntu 14.04 distro has no firewall enabled ? In which case at least a link to this would be good to add: https://www.digitalocean.com/community/tutorials/how-to-setup-a-firewall-with-ufw-on-an-ubuntu-and-debian-cloud-server
Finally I think some specific link to setting up ssh keys would be recommendable as well.
keithy12:Thanks I added why to use nginx, and a small section on using ufw at the end.
Good point about the SSH, I think I will write a paragraph or two about how to setup a deploy script so you can quickly push changes from dev to the server and that will require SSH setup to be explained.
bankslain:nginx is pretty good to learn, it's good for newbies to learn how to set up subdomains for their projects.
v89cs:./demo_webapp &
If you're exposing your project to the internet you probably at least want your app to auto-restart when it crashes or when the server reboots. Also, it might be an idea to run it as nobody instead of with your usual user account.
elithrar:Thanks, I actually don't know how to do this but I will investigate and add to the guide once I know how to do it and how to explain it.
dwevlo:See here: http://elithrar.github.io/article/running-go-applications-in-the-background/
Supervisord is one way to do it, as it Upstart (someone provided an example) or systemd. I prefer Supervisor as it's cross-platform/portable across OS versions (hey, Debian!).
v89_cs:You need to create an upstart script. For example: (in /etc/init/demo-webapp.conf)
description "demo-webapp" start on (started networking) respawn chdir /home/apps exec /home/apps/demo-webapp
Then
sudo initctl start demo-webapp
.Also most web apps have extra files, so I would rsync a whole folder over (the binary and any static js, css, images, etc)
v89_cs:Thanks I will check this out, if you want I can credit you for this in the guide, PM me if you care about that.
Yes Im going to expand on the rsync, and explain how to create a deploy scripts to push changes easily to the server.
010a:I've added this now after testing it and credited you in the paragraph, thanks!
faendriel:Its worth noting that choosing upstart for this part might not be such a good idea. Upstart is being replaced by systemd in ubuntu 15.04 (literally days from being released). It'll still be in 14.04 LTS until 16.04 comes out a year from now, but it might be worthwhile to include instructions for systemd as well.
q1t:what exactly is the benefit of nginx? can't I just SNAT to port 3000 from 80?
v89_cs:it also handles https for all your apps on the server and deals with caching, and could work as a load balancer. That why I would prefer some kind of proxy server between my web apps and the wild. haproxy is another good alternative.
AnAge_OldProb:I don't know, my intention is to have multiple apps on 1 server so I can hit a subdomain on port 80 and it will route to a specific Go app running on port Y
If I go to the main domain it will go to another app and so on
I then don't have to bog down any of my individual apps with this routing logic and can let nginx handle it all
warmans:It's also a lot faster at serving static assets if you need to gain some performance there.
You really need to package your application rather than manually creating all the scripts on the live server.
There are various projects that make it easier to build all the package types from a single spec. Effing-package-manager is a popular one.
Even if you don't actually package it as a deb or rpm you should still be able to install from source using a makefile or similar. It's pretty easy to do. Here is an example: https://github.com/warmans/fluentd-monitor/blob/master/Makefile#L17
