我一直在尝试在 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 文件中的导入语句如下所示:
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}" />
/app文件夹下的init.py文件中包含如下语句:
app.static_folder = 'static'
知道为什么浏览器找不到 CSS 文件吗??? 感谢所有的帮助。
最佳答案
在 .conf 文件中有一个我之前没有注意到的拼写错误:
Alias /static /var/www/webstie/app/static
将其固定为“网站”,现在一切正常。
关于python - 找不到 apache2 flask 应用程序 css 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54782861/