媒体文件不会与Nginx一起显示,但是静态文件会

时间:2019-08-26 05:32:14

标签: python django nginx media digital-ocean

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

nginx站点配置文件: screenshot 2

网站: screenshot 3

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/"

2 个答案:

答案 0 :(得分:0)

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

sudo setenforce 0

答案 1 :(得分:0)

好吧,我明白了... 问题出在: /etc/nginx/nginx.conf 默认值为: (在文件顶部) 用户www-data; 然后我将其更改为: 用户admin_aljaz; 一切开始起作用:D