As the title says
A story when a Django application is placed under / home / ec2-user /
on AWS
WEB server uses Nginx
When publishing a Django application, static files
$ python manage.py collectstatic
Need to be put together somewhere
settings.py looks like this
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS=(
os.path.join(BASE_DIR, "app/static/"),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
By doing this, various css and js will be collected in / home / ec2-user / django_project_root / static
and can be accessed under http: // domain / static
.
Make nginx.conf accessible to static files as follows
nginx.conf
server {
...
location /static/ {
autoindex on;
alias /home/ec2-user/django_project_root/static/;
}
If you look at the state of the application because it can be done with this, css is not applied (403 forbidden) Looking at /var/log/nginx/error.log
2017/08/29 02:17:27 [error] 11629#0: *22 open() "/home/ec2-user/django_project_root/static/apps/css/base.css" failed (13: Permission denied), client: xx.xxx.xxx.xxx, server: xx.xxx.xxx.xxx, request: "GET /static/apps/css/base.css HTTP/1.1", host: "xx.xxx.xxx.xxx", referrer: "http://xx.xxx.xxx.xxx/"
I got a permission error like this
SElinux is bad when I try various googles, isn't it? There was an article like
$ getenforce
Disabled
Was disabled
I tried playing with the permissions of static files and playing with the permissions of the directory / home / ec2-user / django_project_root / static /
, but the state did not change.
The initial state is 700 (drwx ------), but it was necessary to give execute permission to other.
$ sudo chmod o+x /home/ec2-user/
with this
xx.xxx.xxx.xxx - - [29/Aug/2017:02:54:10 +0000] "GET /static/apps/css/login.css HTTP/1.1" 200 1203 "http://xx.xxx.xxx.xxx" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36" "-"
Yes You can now safely access static files
It was a rudimentary story that even if you have execute permission to the child directory, you can not "move to the directory itself" without execute permission to the parent directory ...
Recommended Posts