[英]nginx+django+uwsgi static files 403 Forbidden
嗨〜我在CentOS 6.5中部署了一個網站。 該框架是django1.7。 我使用nginx和uwsgi。
該網站現在可用,除了403 Forbidden所有靜態文件。
我用google搜索了幾個小時,並將整個站點文件夾更改為chmod 777.文件夾的所有者是kltc,nginx.conf中的用戶也是kltc。
我不知道為什么問題仍然是權限被拒絕。
nginx.conf
user kltc;
worker_processes 1;
kuaileticao.miyayx.me
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name kuaileticao.miyayx.me; # substitute your machine's IP address or FQDN
charset utf-8;
access_log /srv/www/nginx/kuaileticao.miyayx.me/access.log;
error_log /srv/www/nginx/kuaileticao.miyayx.me/error.log;
location /static {
autoindex on;
alias /home/kltc/Project/sunny_sports/sunny_sports/static;
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass 127.0.0.1:8001;
include uwsgi_params; # the uwsgi_params file you installed
}
}
uwsgi.ini
[uwsgi]
# the base directory (full path)
chdir=/home/kltc/Project/sunny_sports
# Django's wsgi file
module=sunny_sports.wsgi:application
master=true
# maximum number of worker processes
processes=10
# the socket (use the full path to be safe
socket=127.0.0.1:8001
chmod-socket=664
chown-socket=kltc:kltc
pidfile=/tmp/project-master.pid
# clear environment on exit
vacuum=true
max-requests=5000
daemonize=sunny_sports.uwsgi.log
error.log中
[error] 34335#0: *73 open() "/home/kltc/Project/sunny_sports/sunny_sports/static/css/font-awesome.min.css" failed (13: Permission denied), client: 157.7.154.194, server: kuaileticao.miyayx.me, request: "GET /static/css/font-awesome.min.css HTTP/1.1", host: "kuaileticao.miyayx.me", referrer: "http://kuaileticao.miyayx.me/"
[kltc@localhost static]$ pwd /home/kltc/Project/sunny_sports/sunny_sports/static [kltc@localhost static]$ ls -l total 32 4 drwxrwxrwx. 2 kltc kltc 4096 Feb 25 18:51 avatars 4 drwxrwxrwx. 7 kltc kltc 4096 Feb 25 18:51 css 4 drwxrwxrwx. 2 kltc kltc 4096 Feb 25 18:51 custom 4 drwxrwxrwx. 2 kltc kltc 4096 Feb 25 18:51 font 4 drwxrwxrwx. 2 kltc kltc 4096 Feb 25 18:51 fonts 4 drwxrwxrwx. 3 kltc kltc 4096 Feb 25 18:51 images 4 drwxrwxrwx. 2 kltc kltc 4096 Feb 25 18:51 img 4 drwxrwxrwx. 10 kltc kltc 4096 Feb 26 08:18 js
>
[kltc@localhost static]$ ps -aux | grep nginx
root 37444 0.0 0.0 110008 2048 ? Ss 09:02 0:00 nginx: master process /usr/sbin/nginx
kltc 37445 0.0 0.0 112548 3700 ? S 09:02 0:00 nginx: worker process
我嘗試了幾種方法。 例如,將nginx.conf用戶更改為root
。 但它們都沒有奏效。
希望得到你的幫助。 謝謝!
確保你的項目(/ home)的chown父目錄可以被nginx worker讀取。
chown -R kltc:kltc /home
chmod -R ug+r /home
確保在設置文件中聲明了STATIC_ROOT。
另外,在運行服務器之前,嘗試運行python manage.py collectstatic --noinput
。
希望有效!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.