[英]Permission denied /media files Django Nginx setup
I followed this tutorial:我遵循了本教程:
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-22-04 https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-22-04
Everything is working (static files are served etc) but by user uploaded media files show a 'permission denied' when trying to access the image:一切正常(提供静态文件等),但用户上传的媒体文件在尝试访问图像时显示“权限被拒绝”:
2023/01/21 09:50:01 [error] 12912#12912: *266 open() "/home/hvn/intranet/intranet/media/images/werkstujk_1_Far44Li.2e16d0ba.fill-322x247-c100.jpg" failed (13: Permission denied), client: xxx.xxx.xxx.xxx, server: xxxxx.net, request: "GET /media/images/werkstujk_1_Far44Li.2e16d0ba.fill-322x247-c100.jpg HTTP/1.1", host: "www.xxxxxx.net", referrer: "https://www.xxxxx.net/blogs/"
I'm using wagtail as cms system.我正在使用 wagtail 作为 cms 系统。
The Gunicorn socket is running under user 'hvn' and group 'www-data'. Gunicorn 套接字在用户“hvn”和组“www-data”下运行。
The directory and filepermissions are like:目录和文件权限如下:
750 for dirs and 644 for files:目录 750 个,文件 644 个:
ll | grep media
drwxr-xr-x 5 hvn www-data 4096 Jan 17 22:36 media/
-rw-r--r-- 1 hvn www-data 33857 Jan 21 00:24 werkstujk_1_Far44Li.2e16d0ba.fill-322x247-c100.jpg
My nginx config file is serving the media folder:我的 nginx 配置文件正在为媒体文件夹提供服务:
location /media/ {
root /home/hvn/intranet/intranet;
}
/etc/nginx/sites-enabled/xxx.xx
server {
server_name xxx.xx *.xxx.xx;
location = /favicon.ico { access_log off; log_not_found off; }
location /collectstatic/ {
root /home/hvn/intranet/intranet;
}
location /media/ {
root /home/hvn/intranet/intranet;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/xxx.xx/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/xxx.xx/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.xxxx.xx) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = xxx.xx) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name xxx.net *.xxx.xx;
return 404; # managed by Certbot
What am I doing wrong?我究竟做错了什么? Please help me.请帮我。 Thnx in advanced.先进的thnx。
Solved it: Had to set in the nginx.conf that nginx runs on the same user that is serving the website:解决它:必须在 nginx.conf 中设置 nginx 在为网站提供服务的同一用户上运行:
Check the user in /etc/nginx/nginx.conf Change ownership to user.检查 /etc/nginx/nginx.conf 中的用户 将所有权更改为用户。 sudo chown -R nginx:nginx /var/lib/nginx sudo chown -R nginx:nginx /var/lib/nginx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.