写入日志文件时权限被拒绝 [英] Permission Denied when writing log file

查看:539
本文介绍了写入日志文件时权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ubuntu 13.04。我正在使用 sudo服务uwsgi start

I'm using ubuntu 13.04. I'm running uwsgi using sudo service uwsgi start

运行uwsgi我已经在django中将日志文件配置为 /home/shwetanka/logs/mysite/mysite.log

I've configured log file in django as /home/shwetanka/logs/mysite/mysite.log

但是我遇到此错误-

ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/home/shwetanka/logs/mysite/mysite.log'

如何解决?

推荐答案

您需要使用 chmod修复权限。 命令,例如: chmod 775 /home/shwetanka/logs/mysite/mysite.log

You need to fix permissions with the chmod command, like this: chmod 775 /home/shwetanka/logs/mysite/mysite.log.

使用 ls -l /home/shwetanka/logs/mysite/mysite.log 查看文件的所有者,并将其写为 uwsgi 。如果该文件不属于 uwsgi 所拥有,则必须使用 chown 命令。

Take a look at the owner of the file with ls -l /home/shwetanka/logs/mysite/mysite.log and make it writable to uwsgi. If the file isn't owned by uwsgi, you'll have to use the chown command.

看看使用 ps aux来运行服务的用户名| grep'uwsgi'

如果当前安全性对您而言并不那么重要,请使用 chmod 777 /home/shwetanka/logs/mysite/mysite.log 就是这样。

If the security isn't so important to you at the moment, use chmod 777 /home/shwetanka/logs/mysite/mysite.log and that's it. But that's not the way how this is done.

最安全的方法是检查文件的所有者和文件组,然后在必要时进行更改。

The safest way to do this would be to check the owner and the group of the file and then change them if necessary and adjust the permissions accordingly.

让我们举个例子。

如果我在<$ c $中有文件c> /home/shwetanka/logs/mysite/mysite.log 和命令 ls -l /home/shwetanka/logs/mysite/mysite.log给出以下输出:

If I have a file in /home/shwetanka/logs/mysite/mysite.log and the command ls -l /home/shwetanka/logs/mysite/mysite.log gives the following output:

-rw-rw-r-- 1 shwetanka shwetanka 1089 Aug 26 18:15 /home/shwetanka/logs/mysite/mysite.log

这表示文件的所有者为 shwetanka ,该组也是 shwetanka 。现在,让我们阅读 rwx 位。第一组与文件所有者有关,因此 rw-意味着文件可由所有者读取和写入,由组读取和写入,而由其他用户读取和写入。您必须确保文件的所有者是正在尝试向其写入内容的服务,或者该文件属于该服务的组,否则您将获得权限被拒绝错误。

it means that the owner of the file is shwetanka and the group is also shwetanka. Now let's read the rwx bits. First group is related to the file owner, so rw- means that the file is readable and writable by the owner, readable and writeable by the group and readable by the others. You must make sure that the owner of the file is the service that's trying to write something to it or that the file belongs to group of the service or you'll get a permission denied error.

现在,如果我拥有USWGI服务使用的用户名 uwsgi ,并希望上述文件能够通过该服务可写,我必须更改文件的所有者,例如:

Now if I have a username uwsgi that's used by the USWGI service and want the above file to be writable by that service, I have to change the owner of the file, like this:

chown uwsgi / home / shwetanka / logs / mysite /mysite.log 。由于所有者的写位(第一个 rwx 组)已设置为 1 ,因此该文件现在为由UWSGI服务编写。如有其他疑问,请发表评论。

chown uwsgi /home/shwetanka/logs/mysite/mysite.log. Since the write bit for the owner (the first rwx group) is already set to 1, that file will now be writable by the UWSGI service. For any further questions, please leave a comment.

这篇关于写入日志文件时权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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