媒体文件不会出现在 nginx 中,但静态文件会

Media files wont show up with nginx, but static files will

我在配置 nginx 时遇到问题。我的媒体文件没有显示。 settings.py:

nginx 站点配置文件:

网站:

nginx/error.log 的一部分:

2019/08/25 20:28:10 [error] 28230#28230: *1 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184012.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184012.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:28:10 [error] 28230#28230: *4 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184214.jpg" failed (2: No such file or directory), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184214.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:28:10 [error] 28230#28230: *5 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184328.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184328.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:28:20 [error] 28230#28230: *5 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184328.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184328.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/admin/web_data/photo_gallery/2/change/"
2019/08/25 20:31:39 [error] 28230#28230: *13 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184328.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184328.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/admin/web_data/photo_gallery/2/change/"
2019/08/25 20:41:29 [error] 28230#28230: *14 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184012.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184012.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:41:29 [error] 28230#28230: *18 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184328.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184328.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:41:29 [error] 28230#28230: *19 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184214.jpg" failed (2: No such file or directory), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184214.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:44:54 [error] 28571#28571: *1 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184012.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184012.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:44:54 [error] 28571#28571: *2 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184214.jpg" failed (2: No such file or directory), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184214.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:44:54 [error] 28571#28571: *5 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184328.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184328.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:46:40 [error] 28571#28571: *6 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184328.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184328.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/admin/web_data/photo_gallery/2/change/"
2019/08/25 20:52:51 [error] 28571#28571: *17 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184328.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184328.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/admin/web_data/photo_gallery/2/change/"
2019/08/25 20:57:43 [error] 28571#28571: *21 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184328.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184328.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:57:43 [error] 28571#28571: *23 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184012.jpg" failed (13: Permission denied), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184012.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"
2019/08/25 20:57:43 [error] 28571#28571: *24 open() "/home/admin_aljaz/patricija_website/media/image/20190816_184214.jpg" failed (2: No such file or directory), client: 78.153.61.113, server: 104.248.83.156, request: "GET /media/image/20190816_184214.jpg HTTP/1.1", host: "104.248.83.156", referrer: "http://104.248.83.156/"

如果您 运行 使用 Centos 7,请尝试 disabling SELinux 使用:

sudo setenforce 0

好的,我知道了... 问题出在: /etc/nginx/nginx.conf 默认是: (在文件的顶部) 用户 www 数据; 然后我将其更改为: 用户 admin_aljaz; 一切都开始工作了:D