nginx + django + uwsgi静态文件403禁止 [英] nginx+django+uwsgi static files 403 Forbidden

查看:575
本文介绍了nginx + django + uwsgi静态文件403禁止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨〜我正在CentOS 6.5中部署一个网站.框架是django1.7.我使用nginx和uwsgi.

Hi~ I'm deploying a website in CentOS 6.5. The framework is django1.7. I use nginx and uwsgi.

该网站现已开放,但所有静态文件的"403禁止访问"除外.

The website is now available except 403 Forbidden for all static files.

我已经搜索了几个小时,并将整个站点文件夹更改为chmod777.文件夹的所有者是kltc,nginx.conf中的用户也是kltc.

I have googled a few hours, and have changed the whole site folder as chmod 777. The owner of folder is kltc, and user in nginx.conf is also kltc.

我不知道为什么问题仍然被拒绝.

I have no idea why the problem is still Permission denied.

nginx.conf

nginx.conf

user  kltc;
worker_processes  1;

kuaileticao.miyayx.me

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.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.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.但是他们都不起作用.

I have tried several methods. Such as, change the nginx.conf user to root. But none of them worked.

希望能为您提供帮助.谢谢!

Hope for your help. Thank you!

推荐答案

请确保您对项目(/home)的父目录进行了整理,以使Nginx工作者可以读取.

Make sure that you chown parent directory of your project (/home) to be readable by the nginx worker.

chown -R kltc:kltc /home 
chmod -R ug+r /home

这篇关于nginx + django + uwsgi静态文件403禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆