在Django应用程序上创建自定义503页面

时间:2015-12-11 18:28:07

标签: python django apache custom-error-pages

以下是我在启用网站的文件夹中的django的apache配置文件。我试图在服务器关闭时使用自定义503页面。但是,使用此django配置时,文档根目录不受尊重。此外,我尝试将其放在/ data / my-app-static之类的别名下,并使用它来生成页面。我做错了什么?我还用我正在尝试的东西注释了配置。

<VirtualHost *:443>
    WSGIDaemonProcess my-app python-path=/data/my-app:/data/my-app-env/lib/python2.7/site-packages
    WSGIProcessGroup my-app
    WSGIScriptAlias / /data/my-app/intel_django/wsgi.py
    WSGIPassAuthorization On

    SetEnv my-app_HOME /data/my-app
    SetEnv my-app_STATIC_DIR /data/my-app-static
    SetEnv my-app_MEDIA_DIR /data/my-app-media

    DocumentRoot /var/www
    ServerAdmin webmaster@localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
    </Directory>

    <Directory "/data/my-app/intel_django">
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>

    Alias /static/media/ "/data/my-app-media"
    Alias /static "/data/my-app-static"


    <Directory "/data/my-app-static">
        Order deny,allow
        Allow from all

        SetOutputFilter DEFLATE
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE text/javascript
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/x-javascript
    </Directory>

    <Directory "/data/my-app-media">
        Order deny,allow
        Allow from all
    </Directory>

    # This line just throws 503 all the time and is being used for testing.
    RewriteEngine On
    RewriteRule ^(.*)$ /$1 [R=503,L]

    # I have a 503.html in /var/www, but doesnt work.
    ErrorDocument 503 /503.html

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
        LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    #SSL Conf
    SSLEngine on
    SSLCertificateFile /etc/apache/ssl/selfsigned.crt
    SSLCertificateKeyFile /etc/apache/ssl/selfsigned.key

</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
    RewriteEngine on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>

0 个答案:

没有答案