I created simple flask site with could of assets/static files. Uploaded it to EC2, server renders templates correctly, but static files absolutely unavailable.
I connected via SSH and checked whether setup all corrent. Path to application root is /opt/python/current/app/
, full path to CSS file /opt/python/current/app/mysite/static/css/stylesheet.css
.
Corresponding alias specified in web console and transfered to Apache's wsgi.conf:
Alias /static/ /opt/python/current/app/mysite/static
<Directory /opt/python/current/app/mysite/static>
Order allow,deny
Allow from all
</Directory>
Trying to get al least CSS file (http://xxx.xxx.us-west-2.elasticbeanstalk.com/static/css/stylesheet.css) - got 404.
Check whether files are in place and static folder pointing to correct location: adding Options + Indexes
to directory section above, opening url http://xxx.xxx.us-west-2.elasticbeanstalk.com/static/
, and see content of my static folder: css, js, lib
.
One more check: adding file 1.css
to static root, opening in browser as directory, see that my file appeared. Trying to get it clicking on this file - got 404 again!
Neither any additional setting was added, nor dotfiles. All dynamic pages are retrieved succesfully.
How to handle static files with EC2?
Solution was simple and dumb: in configuration section where /static/
alias defined I missed trailing slash.
Incorrect: mysite/static
Correct: mysite/static/