简体   繁体   English

为什么在由capistrano生成的文件上部署时出现“权限被拒绝”错误?

[英]Why am I getting Permission denied error in deployment on files generated by capistrano?

I was having a failed: "sh -c 'cd /var/www error. Then fixed it by adding the following in deploy.rb... 我遇到了failed: "sh -c 'cd /var/www -c'cd failed: "sh -c 'cd /var/www错误。然后通过在deploy.rb中添加以下内容来修复它...

set :default_environment, {
  'PATH' => "/var/lib/gems/1.9.1/bin:$PATH"
}

Now I'm getting this new error. 现在,我收到了这个新错误。

 ** [out :: ip.address] Rails Error: Unable to access log file. Please ensure that /var/www/releases/20111208152807/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
 ** [out :: ip.address] mkdir -p /var/www/releases/20111208152807/public/assets
 ** [out :: ip.address] mkdir -p /var/www/releases/20111208152807/public/assets
 ** [out :: ip.address] mkdir -p /var/www/releases/20111208152807/public/assets
 ** [out :: ip.address] 
 ** [out :: ip.address] mkdir -p /var/www/releases/20111208152807/public/assets
 ** [out :: ip.address] mkdir -p /var/www/releases/20111208152807/public/assets
 ** [out :: ip.address] 
 ** [out :: ip.address] rake aborted!
 ** [out :: ip.address] 
 ** [out :: ip.address] Permission denied - /var/www/releases/20111208152807/public/assets/manifest.yml

So I checked the permissions on manifest.yml and production.log with ls -lha and yes, they're owned by root. 所以我用ls -lha检查了manifest.yml和production.log的权限,是的,它们是root拥有的。

The capistrano deployment is being done by a linux user (not root) that owns the /var/www directory . capistrano 部署是由拥有/ var / www目录的linux用户(不是root用户)完成的 I'm guessing it's because whatever command is creating those files is giving them root ownership. 我猜这是因为创建这些文件的任何命令都赋予了它们根目录所有权。

CLARIFICATION : I know that probably just deploying using root will fix the problem but I don't want to use root. 澄清 :我知道可能仅使用root进行部署即可解决该问题,但我不想使用root。

You should never have web application files owned by root , They should be owned by a non privileged user. Web应用程序文件永远不应该由root拥有,它们应该由非特权用户拥有。 While the user varies between web servers and how your web server is set up generally the user is www-data (for Apache) or nobody (for Nginx). 尽管用户在Web服务器之间以及Web服务器的设置方式上各不相同,但用户通常是www-data (对于Apache)或nobody (对于Nginx)。

And to remove your error you want to run the command mentioned in the error: 为了消除错误,您需要运行错误中提到的命令:

chmod 0666 /var/www/releases/20111208152807/log/production.log will set the file to read write permissions for every user. chmod 0666 /var/www/releases/20111208152807/log/production.log会将文件设置为每个用户的读写权限。

Those permissions may be a bit permissive so you can restrict them if you feel the need. 这些权限可能有点宽容,因此您可以根据需要限制它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM