I just finished setting up my CMS (programmed in Go) on my dedicated Linux (Ubuntu Server 14.04) server with NGINX as my primary webserver I wish to utilize to serve static content in addition to the Go (and Node.js) http webserver and instead of using their respective fileservers.
Since this is my first experience with Linux, dedicated servers in general and deploying Go applications online, I'd be very interested in hearing your opinions about good conventions to where we store - ideally - all our different websites/webapplications.
By default NGINX uses /usr/share/nginx/ to serve content from. I know it's the easiest thing in the world to change it to whatever we want, but I like to do things right from the beginning.
Right now I store my CMS (Go application) in /home/[myuser]/gocode/src/[projectname]. This is where the go application resides, but it is also there I have the folders, "public" and "media" which I would ideally serve with NGINX.
Since I'd like to be able to switch webservers and host Apache-, NGINX-, etc- applications inside the same overall root location, I now have second doubts about using /var/www or /var/www/html as my root directory. The reason being that apache uses this location by default, and I don't want to serve my application files - only my static files. Others seem to be using /home/user/public_html but that again, wouldn't work well for different webservers and programming languages/platforms.
Do you have any good arguments as to where we would ideally gather/place all our PHP/Apache, Go/NGINX, Node.js, etc. applications?
I tagged this with go and node.js, since go is my primary programming language of choice and most of my applications will be in that language. I do however also want to host my old PHP and Node.js applications - ideally in the same root directory - depending if you have any gold nuggets to share with me regarding how to organize such a multi-platform environment.
I put all applications in /opt
. When you build your go program you will end up with a single binary. For example suppose you have a project:
gocode/src/github.com/someorg/foo
You would run:
go build -o /tmp/foo
And put that on the server:
/opt/foo/foo
For your static content just copy the files:
/opt/foo/public/images/logo.png
/opt/foo/public/styles/site.css
/opt/foo/public/scripts/site.js
So in this example you only have 4 files, you don't upload any .go
files, and there's no need to match the folder structure you have locally.
For nginx you just need to forward traffic to a port, so it doesn't need to know anything about where files are. Go is more than capable of serving the files out of your public and media directories.
If you need a writeable folder (most web apps are read-only), then I'd recommend storing that data in /tmp
or /var
but not alongside your application.