django - What are the reasons why static files cannot be accessed with 403 errors after migrating nginx to Alibaba Cloud?
伊谢尔伦
伊谢尔伦 2017-05-16 17:13:48
0
2
564

p.s: The Django project can run successfully locally, but it does not work after migrating to Alibaba Cloud.

Running environment: ubuntu14.04+uwsgi+nginx+django1.9.

This is a screenshot of the admin page for accessing Django. All css files cannot be loaded. The detailed error message is posted below.

The location of the project in Alibaba Cloud is /root/mysite.

/etc/nginx/site-enabled/mysite.conf is as follows

server {
    listen 8080;
    server_name www.domainname.com;

    location /static/ {
        alias /root/mysite/blog/static/;
    }

    location / {
        uwsgi_pass 127.0.0.1:8001;
        include     /etc/nginx/uwsgi_params;
    }
}

Additional question: All static files have been collected in the directory specified by my alias

$ python manage.py collectstatic
0 static files copied to '/root/mysite/blog/static', 69 unmodified.

# 文件权限没有问题
$ ll /root/mysite/blog/static
total 16
drwxrwxr-x 4 root root 4096 Oct  5 09:13 ./
drwxrwxr-x 6 root root 4096 Oct  5 15:28 ../
drwxrwxr-x 6 root root 4096 Oct  5 09:13 admin/
drwxrwxr-x 5 root root 4096 Oct  5 09:13 blog/
# mysite/settings.py中已经指定了下面两项,**collectstatic**也收集成功,所以我觉得配置可能不存在问题
# 而且项目在本地能够运行,就是迁移到阿里云后无法运行了,所以是不是可能是阿里云的权限问题。
STATIC_URL="/static/"
STATIC_ROOT = os.path.join(BASE_DIR, 'blog/static')

This is the correctpage of localhost:8080/admin when I was experimenting locally

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
刘奇
alias /root/mysite/blog/static/;

/root The directory is only accessible by root by default. No matter how open the files under it are, it’s useless if nginx can’t access them.

Website files are generally placed under /srv/http.

In addition, if you don’t want your server to be used as a broiler, attack others, send spam, or serve as a free proxy, don’t run web programs with root privileges.

阿神

I don’t know much about it, I just used Alibaba Cloud ECS server to build a blog

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template