设置阿帕奇的DocumentRoot符号链接(为了便于部署) [英] Set apache documentRoot to symlink (for easy deployment)

查看:175
本文介绍了设置阿帕奇的DocumentRoot符号链接(为了便于部署)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在寻找一种方式来指出我们的Apache的DocumentRoot一个符号链接。
例如。的DocumentRoot的/ var / www / html等/ finalbuild

we are looking for a way to point our Apache DocumentRoot to a symlink. E.g. DocumentRoot /var/www/html/finalbuild

finalbuild应指向一个文件夹类似的地方/ home / user中/ build3

finalbuild should point to a folder somewhere like /home/user/build3

当我们进入一个新的版本到/ home /用户/ build4中我们想用一个shell脚本,改变了符号链接finalebuild这个新的目录/ home /用户/ build4中,做一个Apache优雅重启有新的Web应用程序版本运行起来几乎没有风险。

when we move a new build to /home/user/build4 we want to use a shell script that changes the symbolic link "finalebuild" to this new directory /home/user/build4 and do an apache graceful restart to have a new web application version up and running with little risk.

什么是创建符号链接,并使用shell脚本之后更改此链接?最好的办法

What's the best way to create this symlink and to change this link afterwards using the shell script?

推荐答案

我们正在使用Capistrano的采用类似的设置。但是,我们遇到了一些问题:

We're using capistrano to employ a similar setup. However, we've run into a few problems:

切换到设置后,事情似乎是想罚款,但后来我们开始注意到,运行帽部署,即使符号链接已更改为指向朝后头修订版,浏览器仍然会显示旧的页面,即使经过多次刷新,并追加不同的GET参数。

After switching to the setup, things appeared to be going fine, but then we started noticing that after running cap deploy, even though the symlink had been changed to point toward the head revision, the browser would still show the old pages, even after multiple refreshes and appending different GET parameters.

起初,我们还以为是浏览器缓存,所以我们开发通过HTTP标头禁用浏览器缓存,但这并没有改变任何东西。然后,我检查,以确保我们没有做整版的缓存服务器端,而我们没有。但我随后发现,如果我在修订中删除的文件的符号链接用来指向,我们会得到一个404,所以阿帕奇提供了新的页面,但它仍然是继老符号链接,并从可投放的页面错误的目录。

At first, we thought it was browser caching, so for development we disabled browser caching via HTTP headers, but this didn't change anything. I then checked to make sure we weren't doing full-page caching server-side, and we weren't. But I then noticed that if I deleted a file in the revision the symlink used to point to, we would get a 404, so Apache was serving up new pages, but it was still following the "old symlink" and serving the pages up from the wrong directory.

这是对共享主机,所以我不能重新启动Apache。所以,我想删除符号链接,并每次都创建一个新的。这似乎工作的有时的,但并不可靠。它的工作时间大概25〜50%。

This is on shared hosting, so I wasn't able to restart Apache. So I tried deleting the symlink and creating a new one each time. This seemed to work sometimes, but not reliably. It worked probably 25~50% of the time.

最后,我发现,如果我:

Eventually, I found that if I:


  1. 删除现有的符号链接(在删除或重命名它);

  2. 做了一个页面请求,从而导致Apache将试图解析符号链接,但发现它失踪(导致404)

  3. 然后创建一个新的符号链接到新的目录

它会导致文档根被正确地更新的大部分时间。然而,即使这不是完美的,时间约2-5%,当部署脚本运行的wget 重命名旧符号链接后,抓取网页的权利,它将返回旧页面,而不是404。

it would cause the docroot to be updated properly most of the time. However, even this isn't perfect, and about 2-5% of the time, when the deploy script ran wget to fetch a page right after renaming the old symlink, it would return the old page rather than a 404.

好像阿帕奇要么是缓存文件系统,或者在 MV 命令只在内存中更改的文件系统,而阿帕奇从磁盘文件系统中读取(不真正使任何意义)。在任何情况下,我已经采取了别人的建议,将运行同步之后的符号链接的变化,这应该得到的文件系统的磁盘上的同步与记忆,也许是轻微的延迟也有利于的wget 返回了404。

It seems like Apache is either caching the filesystem, or perhaps the mv command only changed the filesystem in memory while Apache was reading from the filesystem on disk (doesn't really make any sense). In either case, I've taken up someone's recommendation to run sync after the symlink changes, which should get the filesystem on disk in sync with memory, and perhaps the slight delay will also help the wget to return a 404.

这篇关于设置阿帕奇的DocumentRoot符号链接(为了便于部署)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆