Python Django-带有mod_wsgi的Apache不提供静态文件

Python Django-带有mod_wsgi的Apache不提供静态文件,python,django,apache,Python,Django,Apache,我正在使用Apache和mod_wsgi为项目及其静态文件提供服务 我使用了官方文档,除了没有找到静态文件外,一切都正常。我还没有找到任何好的方法来调试这个问题,甚至没有得到一条可以指出错误的特定消息 到目前为止我所做的: 仔细检查静态文件是否正确放置在静态文件目录中。它们是由收藏家收集的 已检查文件权限 设置。py: [..] DEBUG = False STATIC_ROOT = '/var/www/djangoProject/static-files' STATIC_URL = '/s

我正在使用Apache和mod_wsgi为项目及其静态文件提供服务

我使用了官方文档,除了没有找到静态文件外,一切都正常。我还没有找到任何好的方法来调试这个问题,甚至没有得到一条可以指出错误的特定消息

到目前为止我所做的:

  • 仔细检查静态文件是否正确放置在静态文件目录中。它们是由收藏家收集的
  • 已检查文件权限
设置。py:

[..]
DEBUG = False
STATIC_ROOT = '/var/www/djangoProject/static-files'
STATIC_URL = '/static/'
WSGIDaemonProcess djangoProject

WSGIProcessGroup djangoProjectGroup
WSGIApplicationGroup %{GLOBAL}

WSGIPythonHome /var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath /var/www/djangoProject/

WSGIScriptAlias / /var/www/djangoProject/djangoProject/wsgi.py
<Directory /var/www/djangoProject/djangoProject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static/ /var/www/djangoProject/static-files/
<Directory  /var/www/djangoProject/static-files>
    Require all granted
</Directory>
"GET /static/app01/css/default.css HTTP/1.1" 404 346 "http://example.com/"
Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/
WSGIDaemonProcess djangoProject

WSGIProcessGroup djangoProjectGroup
WSGIApplicationGroup %{GLOBAL}

WSGIPythonHome /var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath /var/www/djangoProject/

Alias /static/ /var/www/djangoProject/static-files/
<Directory /var/www/djangoProject/static-files>
    Require all granted
</Directory>

WSGIScriptAlias / /var/www/djangoProject/djangoProject/wsgi.py
<Directory /var/www/djangoProject/djangoProject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
Apache设置:

[..]
DEBUG = False
STATIC_ROOT = '/var/www/djangoProject/static-files'
STATIC_URL = '/static/'
WSGIDaemonProcess djangoProject

WSGIProcessGroup djangoProjectGroup
WSGIApplicationGroup %{GLOBAL}

WSGIPythonHome /var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath /var/www/djangoProject/

WSGIScriptAlias / /var/www/djangoProject/djangoProject/wsgi.py
<Directory /var/www/djangoProject/djangoProject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static/ /var/www/djangoProject/static-files/
<Directory  /var/www/djangoProject/static-files>
    Require all granted
</Directory>
"GET /static/app01/css/default.css HTTP/1.1" 404 346 "http://example.com/"
Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/
WSGIDaemonProcess djangoProject

WSGIProcessGroup djangoProjectGroup
WSGIApplicationGroup %{GLOBAL}

WSGIPythonHome /var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath /var/www/djangoProject/

Alias /static/ /var/www/djangoProject/static-files/
<Directory /var/www/djangoProject/static-files>
    Require all granted
</Directory>

WSGIScriptAlias / /var/www/djangoProject/djangoProject/wsgi.py
<Directory /var/www/djangoProject/djangoProject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
Apache访问日志:

[..]
DEBUG = False
STATIC_ROOT = '/var/www/djangoProject/static-files'
STATIC_URL = '/static/'
WSGIDaemonProcess djangoProject

WSGIProcessGroup djangoProjectGroup
WSGIApplicationGroup %{GLOBAL}

WSGIPythonHome /var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath /var/www/djangoProject/

WSGIScriptAlias / /var/www/djangoProject/djangoProject/wsgi.py
<Directory /var/www/djangoProject/djangoProject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static/ /var/www/djangoProject/static-files/
<Directory  /var/www/djangoProject/static-files>
    Require all granted
</Directory>
"GET /static/app01/css/default.css HTTP/1.1" 404 346 "http://example.com/"
Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/
WSGIDaemonProcess djangoProject

WSGIProcessGroup djangoProjectGroup
WSGIApplicationGroup %{GLOBAL}

WSGIPythonHome /var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath /var/www/djangoProject/

Alias /static/ /var/www/djangoProject/static-files/
<Directory /var/www/djangoProject/static-files>
    Require all granted
</Directory>

WSGIScriptAlias / /var/www/djangoProject/djangoProject/wsgi.py
<Directory /var/www/djangoProject/djangoProject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
apache2.conf:

[..]
DEBUG = False
STATIC_ROOT = '/var/www/djangoProject/static-files'
STATIC_URL = '/static/'
WSGIDaemonProcess djangoProject

WSGIProcessGroup djangoProjectGroup
WSGIApplicationGroup %{GLOBAL}

WSGIPythonHome /var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath /var/www/djangoProject/

WSGIScriptAlias / /var/www/djangoProject/djangoProject/wsgi.py
<Directory /var/www/djangoProject/djangoProject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static/ /var/www/djangoProject/static-files/
<Directory  /var/www/djangoProject/static-files>
    Require all granted
</Directory>
"GET /static/app01/css/default.css HTTP/1.1" 404 346 "http://example.com/"
Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/
WSGIDaemonProcess djangoProject

WSGIProcessGroup djangoProjectGroup
WSGIApplicationGroup %{GLOBAL}

WSGIPythonHome /var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath /var/www/djangoProject/

Alias /static/ /var/www/djangoProject/static-files/
<Directory /var/www/djangoProject/static-files>
    Require all granted
</Directory>

WSGIScriptAlias / /var/www/djangoProject/djangoProject/wsgi.py
<Directory /var/www/djangoProject/djangoProject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
Mutex文件:${APACHE\u LOCK\u DIR}默认值
PidFile${APACHE_PID_文件}
超时300
继续
MaxKeepAliveRequests 100
保持超时
用户${APACHE\u RUN\u User}
组${APACHE\u RUN\u Group}
主机名查询
ErrorLog${APACHE_LOG_DIR}/error.LOG
日志级别警告
包括可选mods启用/*.加载
IncludeOptional mods enabled/*.conf
Include ports.conf
选项如下符号链接
不允许超限
要求全部拒绝
不允许超限
要求所有授权
选项索引跟随符号链接
不允许超限
要求所有授权
AccessFileName.htaccess
要求全部拒绝
日志格式“%v:%p%h%l%u%t\%r\“%>s%O\”%{Referer}i\“\”%{User-Agent}i\\”vhost\u
日志格式“%h%l%u%t\%r\”%>s%O\“%%{Referer}i\\\“%%{User Agent}i\\”组合
日志格式“%h%l%u%t\%r\“%>s%O”通用
日志格式“%{Referer}i->%U”Referer
日志格式“%{User agent}i”代理
IncludeOptional conf enabled/*.conf
已启用IncludeOptional站点/
我找到了一个很好的答案“”

  • 顺序是相关的,静态文件的别名必须排在第一位
Apache设置:

[..]
DEBUG = False
STATIC_ROOT = '/var/www/djangoProject/static-files'
STATIC_URL = '/static/'
WSGIDaemonProcess djangoProject

WSGIProcessGroup djangoProjectGroup
WSGIApplicationGroup %{GLOBAL}

WSGIPythonHome /var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath /var/www/djangoProject/

WSGIScriptAlias / /var/www/djangoProject/djangoProject/wsgi.py
<Directory /var/www/djangoProject/djangoProject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Alias /static/ /var/www/djangoProject/static-files/
<Directory  /var/www/djangoProject/static-files>
    Require all granted
</Directory>
"GET /static/app01/css/default.css HTTP/1.1" 404 346 "http://example.com/"
Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/
WSGIDaemonProcess djangoProject

WSGIProcessGroup djangoProjectGroup
WSGIApplicationGroup %{GLOBAL}

WSGIPythonHome /var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath /var/www/djangoProject/

Alias /static/ /var/www/djangoProject/static-files/
<Directory /var/www/djangoProject/static-files>
    Require all granted
</Directory>

WSGIScriptAlias / /var/www/djangoProject/djangoProject/wsgi.py
<Directory /var/www/djangoProject/djangoProject>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
WSGIDaemonProcess项目
WSGIProcessGroup项目组
WSGIApplicationGroup%{GLOBAL}
WSGIPythonHome/var/www/djangoProject/venv/lib/python2.7/site-packages
WSGIPythonPath/var/www/djangoProject/
别名/static//var/www/djangoProject/static文件/
要求所有授权
WSGIScriptAlias//var/www/djangoProject/djangoProject/wsgi.py
要求所有授权

如何加载apache配置文件?你能展示你的主httpd.conf吗?我包括了与静态文件相关的主apache2.conf,但是你如何设置Python虚拟环境有点混乱。确保您阅读了正确的方法。当您运行
ls-las/var/www/djangoProject/static files
时,您会得到什么。它显示了“app01”和“admin”目录谢谢!。为张贴此。。我的问题不是反复检查我的文档根目录,而是花了8个小时试图修复它。。不过这帮了大忙……救了我一天!非常感谢。