简体   繁体   中英

Django; AWS Elastic Beanstalk ERROR: Your WSGIPath refers to a file that does not exist

I am using this tutorial: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html

I create the .ebextensions directory inside the root directory, and put this django.config file in it:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: mysite/wsgi.py

I've also tried setting the path to mysite/mysite/wsgi.py because I saw that work somewhere but it did not help me.

Everywhere I look shows a different .config file with different arrangements, and I don't know where to go from here. How can I properly set my WSGIPath in Elastic Beanstalk?

[Solution]

1 eb config

2 Change the WSGIPath there from application.py to mysite/wsgi.py

That's It

I ran into a similar issue, and it seemed to resolve when I put .elasticbeanstalk in the same directory as .ebextensions, rather than having it be a child directory. Then I had to run eb config to fix the wsgi file that it was de facto picking up, and now I have a running app.

Make sure that .ebextensions isn't ignored. EB looks for .ignore file (.ebignore by default and if it doesnt exists but .gitignore does, it will use it) and deploy only the files that are not ignored. Had a similar issue with my local_settings.

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-ebignore

If you see the following error:

ERROR: Your WSGIPath refers to a file that does not exist.

Note the following:

  1. EC2 (server) instances in EB (platform) run Apache.
  2. Apache finds Python apps according to our WSGIPATH.
  3. By default EB assumes the WSGI file is called application.py.

There are two ways of correcting this.

Option 1: Using environment-specific configuration settings

Run: $ eb config

Find the following config file “.elasticbeanstalk/src-test.env.yml.” This file doesn't actually exist locally; EB pulled it so that you can edit it. If you save changes in this pseudo-file, EB will update the corresponding settings in your env.

If you search for the terms 'WSGI' in the file, you should find a config section resembling this:

aws:elasticbeanstalk:container:python:
  NumProcesses: '1'
  NumThreads: '15'
  StaticFiles: /static/=static/
  WSGIPath: application.py

Update the WSGIPath:

 aws:elasticbeanstalk:container:python:
   NumProcesses: '1'
   NumThreads: '15'
   StaticFiles: /static/=static/
   WSGIPath: src/src/wsgi.py #src/src is an example. Do not just c&p.

If you save the file, EB will update the env config automatically.

The advantage to using the $ eb config method to change settings is that you can specify different settings per env.

Option 2: Using global configuration settings

To use this option, create a new file called /.ebextensions/02_python.config:

option_settings:
  "aws:elasticbeanstalk:application:environment":
    DJANGO_SETTINGS_MODULE: “src.settings" #src is an example.
    "PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH" #src is an example.
  "aws:elasticbeanstalk:container:python":
    WSGIPath: src/src/wsgi.py #src is an example.
    NumProcesses: 3
    NumThreads: 20
  "aws:elasticbeanstalk:container:python:staticfiles":
    "/static/": "www/static/"

What's happening?

  • DJANGO_SETTINGS_MODULE: "src.settings" - adds the path to the settings module.

  • "PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH" - updates our PYTHONPATH so Python can find the modules in our application.(Note that the use of the full path is necessary.)

  • WSGIPath: src/src/wsgi.py sets our WSGI Path.

  • NumProcesses: 3 and NumThreads: 20 - updates the number of processes and threads used to run our WSGI application.

  • "/static/": "www/static/" sets our static files path.

Run $ git commit (if necessary) and $ eb deploy to update these settings.

I did not use console but GUI.

ERROR: Your WSGIPath refers to a file that does not exist.

where could be problem : Creating .zip file

select all : files of your project (not the project folder)

Note : weworkout is my django project (created by django-admin startproject weworkout)

Right way : select all files

正确的方式

Wrong way : selecting project folder

错误的方式


Also this is the only change you have to do to your django project before uploading

weworkout/.ebextensions/django.config file contains

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: weworkout/wsgi.py

Note : .ebextensions is in same folder as manage.py

Check if your Django.config file was saved with the correct extension. I had the same issue and the problem was that the file was being saved as a TXT file instead of config file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM