使用Git和Nginx远程安装网站 [英] Remotely Installing Websites Using Git with Nginx

查看:87
本文介绍了使用Git和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 have exec sudo -u nginx -g nginx ~/test.sh (test.sh contains the GIT_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 to ubuntu:ubuntu?

我建议:

将您的存储库声明为所有人共享的",如"

似乎可以解决该问题:

我按照提到的帖子将配置设置为 shared = true ,它现在似乎可以正常工作.

I set the config to shared=true as per the post mentioned and it seems to be working now.

这篇关于使用Git和Nginx远程安装网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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