大网数据广告活动
服务器运维问答

nginx permission denied to self signed certificate files for ssl configuration on CentOs

· 52CE 我爱测

Very similar to this question but the solutions there did not solve my problem. I am trying to reverse proxy port 8443 to port 4000 with a self signed certificate. I generated my certificate like this openssl req -newkey rsa:2048…

问题原文

原帖链接 · RusinaRange · CC BY-SA 3.0

Very similar to this question but the solutions there did not solve my problem.

I am trying to reverse proxy port 8443 to port 4000 with a self signed certificate. I generated my certificate like this

openssl req -newkey rsa:2048 -sha256 -nodes -keyout certificate.key -x509 -days 365 -out certificate.pem

And I added a server block to my nginx conf:

server {
  listen 8443 ssl;
  server_name www.mydomain.io;
  ssl_certificate /home/user/certificate.pem;
  ssl_certificate_key /home/user/certificate.key;

  location / {
    proxy_pass http://localhost:4000/;
  }
}

But now when I try to start nginx with systemctl start nginx I get the following error:

Sep 10 06:38:52 Elixir systemd[1]: Starting The nginx HTTP and reverse proxy server...
Sep 10 06:38:52 Elixir nginx[25347]: nginx: [emerg] BIO_new_file("/home/user/certificate.pem") failed (SSL: error:0200100D:system library:fopen:Permission denied:fopen('/home/user/certificate.pem','r') error:2006D002:BIO routines:BIO_new_file:system lib)
Sep 10 06:38:52 Elixir nginx[25347]: nginx: configuration file /etc/nginx/nginx.conf test failed

Edit: The files have 777 permissions but are not owned by the nginx user.

已采纳解答

原帖链接 · RusinaRange · CC BY-SA 4.0

This problem was very likely due to selinux labeling the file as something insecure like unconfined_u therefore denying access to it no matter what the permissions of the file are. The labels for a file can be checked by running ls -Z.

The solution is to change the label (aka selinux context) of the file to something that nginx permitted to open:

chcon -t httpd_config_t /path/to/file

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。