我已经configurationnginx通过socket运行django站点:
fastcgi_pass unix:/tmp/django.socket;
现在我(手动)运行
./manage.py runfcgi socket=/tmp/django.socket
http请求导致502坏的网关,并且错误如下:
连接()到unix:/tmp/django.socket失败(13:权限被拒绝),当连接到上游时,
我应该设置什么权限,才能够轻松重启django fcgi?
Nginx运行在某些用户(在Debian上通常是www-data),你可以通过以下方式检查:
ps aux | grep nginx | grep worker
用户将在第一列。
这个用户必须有权访问/tmp/django.socket来进行写作和阅读。 你可以通过在运行nginx的相同用户下运行django来解决这个问题(例如,Debian上的www-data),或者你必须将nginx用户添加到同一组中,作为用户,你正在运行django,并且socket必须有权读取和写入组。
第一个解决scheme是简单的(对我来说)更好。
我有这个问题。 我正在通过unix套接字(在fedora 19上)运行的Gunicorn上运行django站点。 但是nginx没有启动。 我看到了nginx-errors.log文件
2014/03/15 04:25:01 [crit] 18309#0: *422 connect() to unix:/webapps/django/run/gunicorn.sock failed (13: Permission denied) while connecting to upstream
我正确设置了所有文件权限和所有者。 最后我知道这是SElinux的原因,在这里find了解决办法
以下是第一条评论
我提供的链接上描述的解决scheme非常长。 所以我只是在这里复制这个解决scheme的一部分 –
一个快速的解决scheme是禁用selinux
setenforce 0
该命令禁用所有程序的selinux。 要允许nginx在启用selinux的情况下读取unix套接字,请执行以下步骤 –
默认情况下,SELinux日志消息通过Linux审计系统auditd写入/var/log/audit/audit.log 。 如果auditd守护进程没有运行,那么消息被写入/var/log/messages 。 SELinux日志消息标有AVC关键字,这样它们可以很容易地从其他消息中过滤掉,就像使用grep一样。
所以,通过在/var/log/audit/audit.logloggingnginx,我发现了那些相对的AVC消息,这些消息表明的确是否定了与gitlab.socket的nginx连接。
type=AVC msg=audit(1377542938.307:248364): avc: denied { write } for pid=2597 comm="nginx" name="gitlab.socket" dev="vda1" ino=1180273 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=sock_file type=AVC msg=audit(1377542938.307:248364): avc: denied { connectto } for pid=2597 comm="nginx" path="/home/git/gitlab/tmp/sockets/gitlab.socket" scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:system_r:initrc_t:s0 tclass=unix_stream_socket`
使用名为audit2allow的工具,我们可以清除AVC消息。 如果您没有安装它,则随附policycoreutils-devel软件包。
grep nginx /var/log/audit/audit.log | audit2allow
结果是:
#============= httpd_t ============== #!!!! This avc is allowed in the current policy allow httpd_t http_cache_port_t:tcp_socket name_connect; # !!! This avc is allowed in the current policy allow httpd_t httpd_log_t:file setattr; #!!!! This avc is allowed in the current policy allow httpd_t httpd_sys_content_t:sock_file write; #!!!! This avc is allowed in the current policy allow httpd_t initrc_t:unix_stream_socket connectto; #!!!! This avc is allowed in the current policy allow httpd_t user_home_dir_t:dir search; #!!!! This avc is allowed in the current policy allow httpd_t user_home_t:dir { search getattr }; #!!!! This avc is allowed in the current policy allow httpd_t user_home_t:sock_file write; #!!!! This avc is allowed in the current policy allow httpd_t var_run_t:file { read write };
这些是SELinux应该使用的策略。 请注意,user_home是必不可less的,因为GitLab的APP_ROOT位于/ home / git /中。 同样,您会注意到与被拒绝套接字连接有关的策略:unix_stream_socket connectto。
然后,我们可以继续使用audit2allow来创build自定义策略模块,以允许执行以下操作:
grep nginx /var/log/audit/audit.log | audit2allow -M nginx semodule -i nginx.pp`
我们可以通过用semodule -l列出加载的模块来检查加载的策略模块。
之后,请记住使用setenforce 1再次启用SELinux。