Go / Node.js / PHP + NGINX / Apache 网站根目录约定 / 最佳实践

huangapple go评论89阅读模式
英文:

Go / Node.js / PHP + NGINX / Apache web root directory conventions / best practices

问题

我刚刚完成了在我的专用Linux服务器(Ubuntu Server 14.04)上设置我的CMS(使用Go编程),并将NGINX作为我的主要Web服务器来提供静态内容,以及Go(和Node.js)HTTP Web服务器,而不是使用它们各自的文件服务器。

由于这是我第一次接触Linux、专用服务器以及在线部署Go应用程序,我非常希望听听您对存储所有不同网站/ Web应用程序的最佳约定的意见。

默认情况下,NGINX使用/usr/share/nginx/来提供内容。我知道更改为任何我们想要的内容是非常容易的,但我喜欢从一开始就做对。

现在,我将我的CMS(Go应用程序)存储在/home/[myuser]/gocode/src/[projectname]中。这是Go应用程序所在的位置,但也是我拥有"public"和"media"文件夹的位置,我希望能够用NGINX来提供这些文件夹中的内容。

由于我希望能够在同一个根目录下切换Web服务器并托管Apache、NGINX等应用程序,我现在对将/var/www或/var/www/html作为我的根目录有所疑虑。原因是Apache默认使用此位置,而我不希望提供应用程序文件,只提供静态文件。其他人似乎使用/home/user/public_html,但对于不同的Web服务器和编程语言/平台,这也不太适用。

您是否有任何好的理由,可以告诉我们理想的位置来收集/放置所有PHP/Apache、Go/NGINX、Node.js等应用程序?

我在标签中加入了go和node.js,因为go是我首选的主要编程语言,我的大多数应用程序将使用该语言编写。但我也希望托管我的旧PHP和Node.js应用程序-最好在同一个根目录下-如果您对如何组织这样一个多平台环境有任何建议的话。

英文:

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.

答案1

得分: 0

我将所有的应用程序放在/opt目录下。当你构建你的Go程序时,你将得到一个单独的二进制文件。例如,假设你有一个项目:

gocode/src/github.com/someorg/foo

你可以运行:

go build -o /tmp/foo

然后将其放在服务器上:

/opt/foo/foo

对于静态内容,只需复制文件:

/opt/foo/public/images/logo.png
/opt/foo/public/styles/site.css
/opt/foo/public/scripts/site.js

所以在这个例子中,你只有4个文件,不需要上传任何.go文件,并且不需要匹配你本地的文件夹结构。

对于nginx,你只需要将流量转发到一个端口,所以它不需要知道文件的位置。Go完全可以从你的public和media目录中提供文件。

如果你需要一个可写的文件夹(大多数Web应用程序是只读的),那么我建议将数据存储在/tmp/var中,但不要与你的应用程序放在一起。

英文:

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.

huangapple
  • 本文由 发表于 2015年1月6日 02:54:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/27785959.html
  • apache
  • directory-structure
  • go
  • nginx
  • node.js
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定