When I deploy the Django app on AWS Elastic Beanstalk, I can't see the static directory.

Asked 2 years ago, Updated 2 years ago, 78 views

I'm about to publish a project made with python 3.4, django 1.7 on AWS Elastic Beanstalk.

The deployment was successful and I was able to access it with a browser, but the directory containing the static files is 403 errors.
Below is an excerpt of the folder configuration and related settings.

Can anyone tell me the solution?

 -- --myapp
│   -- --myapp
│   │ -- -- settings.py
│   │ -- wsgi.py
│   -- -- manage.py
│   -- -- Static files such as static#CSS/JS/Images
│   │ i -- img
│   │ j --js
│   s --ass
│   ----web
├-- requirements.txt
├-- .elasticbeanstalk
│   ----config.yml
└-- .ebextensions
    ├-- 00_pkg.config
    └-- 01 - web.config

settings.py

STATIC_URL='/static/'
STATICFILES_DIRS=(
    os.path.join(BASE_DIR, 'static',
)

01 - web.config

container_commands:
    01_ migrate:
        command: "django-admin.py migrate"
        leader_only —true
option_settings:
    "aws:elasticbeanstalk:application:environment":
        DJANGO_SETTINGS_MODULE: "myapp.settings"
        PYTHONPATH: "/opt/python/ondeck/app/myapp:/opt/python/current/app/myapp:$PYTHONPATH"
    "aws:elasticbeanstalk:container:python":
        WSGIPath: myapp/myapp/wsgi.py
        NumProcesses—3
        NumThreads: 20
    "aws:elasticbeanstalk:container:python:staticfiles":
        "/static/": "myapp/static/"

Thank you for your cooperation.

python aws django aws-elasticbeanstalk

2022-09-30 16:56

1 Answers

Now that I've solved it myself, I'll write down the results.

There was no problem with the Elastic Beanstalk deployment settings in the question section.
There were two other problems.

One is permission.
Static file permissions within the project to be deployed contained a large number of 640s.I could see it well when I tested it locally, but there was a permission error log left.

/var/log/httpd/error_log

[Sun Nov 29 23:38:36.263454 2015][core:error][pid18065](13) Permission denied:[client172.31.31.43:40497] AH00132: file permissions deny server access: /opt/python/current/app/myapp/static/ihoge.jpohoge:http://myapp.elasticbeanstalk.com/

The permission error was resolved by setting the permission in the local project to 644 and doing "eb deploy" again, but I added the following to the deployment settings to make sure.

container_commands:
    99_staticdir_permission:
        command : find dirrent/static/-type d-print | xargs chmod 755
    99_staticfile_permission:
        command: find dirrent/static/-type f-print | xargs chmod 644

The second problem was symbolic links.
I placed a subdirectory under the static directory, such as bootstrap, but the bootstrap directory name contained the version name, and I made a symbolic link and called it.

myapp/static/
├-- bootstrap->bootstrap-3.3.5
├-- bootstrap - 3.3.5

Call this in the django template

<link rel="stylesheet" href="{%static'bootstrap/css/bootstrap.min.css'%}"/>
<script type="text/javascript" src="{%static'bootstrap/js/bootstrap.min.js'%}"></script>

However, when I deploy with "eb deploy", it doesn't seem to reflect the symbolic link, and when I logged in remotely and looked at the directory, there was no symbolic link.
Therefore, by changing the bootstrap call point of the template to the real directory name, it now appears successfully.

This problem has now been resolved.
Although I was able to resolve myself this time, I would like to thank Stackoverflow and the community for this opportunity.


2022-09-30 16:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.