donglvchu9143 2015-01-05 18:54
浏览 96
已采纳

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

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条回答 默认 最新

  • dongyata3336 2015-05-13 23:15
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用