Nginx,uwsgi,django,ubuntu 16问题w /静态文件

时间:2016-07-21 01:00:09

标签: django ubuntu nginx uwsgi

我正在使用Nginx,uwsgi,django和Ubuntu 16.04,并在我的所有静态文件上获得404。当我查看nginx的error.log时,它会在实际文件位置前面添加一个额外的/ static:

404未找到: /home/jsmith/firstproj/static_cdn/static/css/bootstrap.css

实际位置: /home/jsmith/firstproj/static_cdn/css/bootstrap.css

我不确定为什么在/css/bootstrap.css前添加/ static。这是我的配置文件:

/var/log/nginx/error.log

2016/07/20 17:34:25 [error] 4424#4424: *22 open() "/home/jsmith/firstproj/static_cdn/static/css/bootstrap.css" failed (2: No such file or directory), client: , server: , request: "GET /static/css/bootstrap.css HTTP/1.1", host: 

/home/jsmith/firstproj/src/blogs/settings.py

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn")

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    ]

的/ etc / nginx的/位点可用/ firstproj

server {
    listen 80;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static {
        root /home/jsmith/firstproj/static_cdn;
    }

    location / {
        include         uwsgi_params;
        uwsgi_pass      unix:/run/uwsgi/firstproj.sock;
    }
}

/etc/systemd/system/uwsgi.service

[Unit]
Description=uWSGI Emperor service
After=syslog.target

[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown jsmith:www-data /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

/etc/uwsgi/sites/firstproj.ini

[uwsgi]
project = firstproj
base = /home/jsmith

chdir = %(base)/%(project)/src
home = %(base)/.virtualenvs/%(project)
module = %(project).wsgi:application

master = true
processes = 5

socket = /run/uwsgi/%(project).sock
chmod-socket = 666
vacuum = true
logto = /var/log/uwsgi/%n.log

1 个答案:

答案 0 :(得分:2)

问题在于nginx的“静态”配置。此代码修复了问题

location /static {
    alias /home/jsmith/firstproj/static_cdn;
}

查看此帖子Nginx -- static file serving confusion with root & alias