使用Git和Nginx远程安装网站 [英] Remotely Installing Websites Using Git with Nginx
问题描述
I've followed the example listed at this site in remotely adding my files to my server, however, I'd like to have all files owned by the nginx:nginx
user:group so that I can access the files from my browser after pushing the files.
如何修改 post-receive
钩子,使 nginx:nginx
成为推送到远程"ubuntu"服务器的文件/文件夹的所有者?
How do I go about amending the post-receive
hook so that nginx:nginx
becomes the owner of the files/folders pushed to the remote 'ubuntu` server?
我尝试了以下 post-receive
挂钩,但是,如果文件正在修改,则会收到错误消息: remote:error:无法取消链接旧的'index.html'(权限被拒绝)
,此处为shell脚本:
I've tried the following post-receive
hook, however, if the file is being amended I receive the error: remote: error: unable to unlink old 'index.html' (Permission denied)
, shell script here:
#!/bin/sh
GIT_WORK_TREE=/var/www/www.foo.com/htdocs
export GIT_WORK_TREE
git checkout -f
exec sudo chown -R nginx:nginx $GIT_WORK_TREE
感谢您的帮助!
推荐答案
通常是进程未释放这些文件(防止git checkout执行其工作)的结果,如"
It is usually the result of a process not releasing those files (preventing the git checkout to do its jobs), as described in "Git Checkout warning: unable to unlink files, permission denied".
但是这也可能是您的 sudo
命令成功运行一次的结果,使您的钩子将来无法执行,因为它不再有权以'git
'用户.
But it could also be the result of your sudo
command to have worked successfully once, making any future execution of your hook fail because it no longer has the right to checkout as the 'git
' user.
在这种情况下,您的钩子应 sudo
作为您当前的git命令的 nginx:nginx
,而不是 chown
的最终结果(网络工作树).
If it is the case, your hook should sudo
as nginx:nginx
your current git command, instead of chown
the end result (the web working tree).
OP确认:
在git
post-receive
钩子中,我现在有exec sudo -u nginx -g nginx〜/test.sh
(test.sh
包含上面的GIT_WORK_TREE
内容).
但是,我遇到另一个权限错误:远程:致命:无法创建'/home/ubuntu/foo.git/index.lock':权限被拒绝
.
运行〜/test.sh
后,是否需要返回到ubuntu:ubuntu
?
In the git
post-receive
hook I now haveexec sudo -u nginx -g nginx ~/test.sh
(test.sh
contains theGIT_WORK_TREE
contents above).
However, I'm getting another permission error:remote: fatal: Unable to create '/home/ubuntu/foo.git/index.lock': Permission denied
.
After running~/test.sh
, do I need to go back toubuntu:ubuntu
?
我建议: