我在我的CentOS 7机器上运行了nginx。 我每天运行一个cron作业,生成新的Diffie-Hellman参数。 它们保存在/etc/ssl/dh/dhparam.pem 。 但SELinux阻止nginx读取这个文件。
这是nginx错误日志中的行:
nginx[3189]: nginx: [emerg] BIO_new_file("/etc/ssl/dh/dhparam.pem") failed (SSL: error:0200100D:system library:fopen:Permission denied:fopen('/etc/ssl/dh/dhparam.pem','r') error:2006D002:BIO routines:BIO_new_file:system lib)
这是审计日志:
type=AVC msg=audit(1473285202.181:334): avc: denied { open } for pid=1393 comm="nginx" path="/etc/ssl/dh/dhparam.pem" dev="dm-1" ino=101646309 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=file type=AVC msg=audit(1473285832.647:743): avc: denied { open } for pid=2958 comm="nginx" path="/etc/ssl/dh/dhparam.pem" dev="dm-1" ino=101646309 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=file type=AVC msg=audit(1473287010.821:803): avc: denied { open } for pid=3083 comm="nginx" path="/etc/ssl/dh/dhparam.pem" dev="dm-1" ino=101646316 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=file type=AVC msg=audit(1473287142.871:826): avc: denied { open } for pid=3118 comm="nginx" path="/etc/ssl/dh/dhparam.pem" dev="dm-1" ino=101646309 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=file type=AVC msg=audit(1473287172.480:843): avc: denied { open } for pid=3134 comm="nginx" path="/etc/ssl/dh/dhparam.pem" dev="dm-1" ino=101646309 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=file type=AVC msg=audit(1473287681.994:866): avc: denied { open } for pid=3189 comm="nginx" path="/etc/ssl/dh/dhparam.pem" dev="dm-1" ino=101646309 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_tmp_t:s0 tclass=file
我不是很熟悉SELinux(我知道我应该学习):如何在不取消SELinux(或将其设置为宽容)的情况下授予nginx访问权限?
SELinux拒绝你访问文件,因为你移动了,而不是从文件系统的其他地方复制到它的最终位置。 因此,它保留了原来的安全上下文,这使得Apache不能访问它。
要解决该问题,请使用restorecon重新标记该文件。
为了避免将来出现问题,请复制文件(并在必要时删除原件)。