apache2 flask app css文件找不到?

时间:2019-02-20 09:25:54

标签: python html css flask apache2

我一直在尝试在apache2上部署Flask应用程序,但是在提供CSS文件时遇到问题。在浏览器中打开我的应用程序后,我在控制台中找不到404错误文件。

文件夹结构如下:

/var/www/website/catalog.wsgi
/var/www/website/app/static/styles.css

apache的.conf文件配置如下:

<VirtualHost *:80>
    ServerName 18.130.209.7
    ServerAlias http://ec2-18-130-209-7.eu-west-2.compute.amazonaws.com
    ServerAdmin admin@18.130.209.7
    WSGIDaemonProcess catalog python-path=/var/www/website:/var/www/website/venv/lib/python2.7/site-packages
    WSGIProcessGroup catalog
    WSGIScriptAlias / /var/www/website/catalog.wsgi
    <Directory /var/www/website/app/>
        Order allow,deny
        Allow from all
    </Directory>
    Alias /static /var/www/webstie/app/static
    <Directory /var/www/website/app/static/>
        Order allow,deny
        Allow from all
    </Directory>
    <Directory /var/www/website/app/api>
        Order allow,deny
        Allow from all
    </Directory>
    <Directory /var/www/website/app/auth>
        Order allow,deny
        Allow from all
    </Directory>
    <Directory /var/www/website/app/site>
        Order allow,deny
        Allow from all
        </Directory>
    <Directory /var/www/website/app/templates>
        Order allow,deny
        Allow from all
    </Directory>
    AliasMatch "(?i)^/([^/]+)/static/(.*)$" "/var/www///static/$2"
    <Directory "var/www/website/app/[^/]+/static/.*">
      Order allow,deny
      Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

index.html文件中的import语句如下:

<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}" />

以下语句包含在/ app文件夹的 init .py文件中:

app.static_folder = 'static'

知道为什么浏览器找不到CSS文件吗??? 感谢所有帮助。

1 个答案:

答案 0 :(得分:0)

.conf文件中我以前没有发现错字:

Alias /static /var/www/webstie/app/static

现在将其修复为“网站”,一切正常。