Nginx不提供Django静态文件(Code Inside)

时间:2017-12-03 01:37:25

标签: django apache nginx debian mod-wsgi

我承认,我是一个有偏见的搜索者...如果我在帖子的标题中没有看到类似的问题,我可能不会点击它。除此之外,我已经完成了我的研究,无法找到适合我的可靠解决方案

问题

我正在使用Apache 2.4mod_wsgi 4.5.22以及尝试使用nginx 1.12.2-1~jessie来提供我的静态文件。我的nginx设置似乎没有提供我的文件。

设置

这是我的 apache2 .conf文件:

...
Alias /robots.txt  /home/user/web/domain.com/public_html/robots.txt
Alias /favicon.ico /home/user/web/domain.com/public_html/favicon.ico

IncludeOptional /home/user/conf/web/apache2.domain.com.conf*

<Directory /home/user/web/domain.com/user/project/>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

<Directory /home/user/web/domain.com/project/app/>
    AllowOverride All 
    Options +Includes
</Directory>

LoadModule wsgi_module "/root/.virtualenvs/user/local/lib/python2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so"

WSGIDaemonProcess domain.com user=user group=user processes=2 threads=25
WSGIProcessGroup domain.com

WSGIPythonHome "/root/.virtualenvs/user"

这是我的 nginx .conf文件:

server {
listen      X.X.X.X:80;
server_name domain.com www.domain.com;
error_log  /var/log/apache2/domains/domain.com.error.log error;

location / { 
    proxy_pass      http://X.X.X.X:8080;
    location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
        root           /home/user/web/domain.com/public_html;
        access_log     /var/log/apache2/domains/domain.com.log combined;
        access_log     /var/log/apache2/domains/domain.com.bytes bytes;
        expires        max;
        try_files      $request_uri @fallback;
    }   
}   

location /error/ {
    alias   /home/user/web/domain.com/document_errors/;
}   

location @fallback {
    proxy_pass      http://X.X.X.X:8080;
}   

location /static {
    autoindex on; 
    alias /home/user/web/domain.com/project/app/static/;
}   

location ~ /\.ht    {return 404;}
location ~ /\.svn/  {return 404;}
location ~ /\.git/  {return 404;}
location ~ /\.hg/   {return 404;}
location ~ /\.bzr/  {return 404;}

include /home/user/conf/web/nginx.domain.com.conf*;}

错误

我目前没有在日志中看到任何问题。

0 个答案:

没有答案