简体   繁体   中英

Target WSGI script wsgi.py' cannot be loaded as Python module

I'm trying to scale my django project with AWS ElasticBeanstalk but i get an error, the error doesn´t appear when I deploy the proyect, but when I scale it I get this error:

 ValueError: Unable to configure handler 'file_log': [Errno 13] Permission 
     denied: '/var/log/meatme/django.log'
 mod_wsgi (pid=4829): Target WSGI script 
    '/opt/python/current/app/meatme/meatme/wsgi.py' cannot be loaded as 
    Python module.
 mod_wsgi (pid=4829): Exception occurred processing WSGI script 
    '/opt/python/current/app/meatme/meatme/wsgi.py'.
 Traceback (most recent call last):
 File "/opt/python/current/app/meatme/meatme/wsgi.py", line 16, in <module>
     application = get_wsgi_application()
 File "/opt/python/run/venv/lib/python2.7/site-
     packages/django/core/wsgi.py", line 13, in get_wsgi_application
     django.setup(set_prefix=False)
 File "/opt/python/run/venv/lib/python2.7/site-packages/django/__init__.py", 
     line 22, in setup
     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
 File "/opt/python/run/venv/lib/python2.7/site-
     packages/django/utils/log.py", line 75, in configure_logging
     logging_config_func(logging_settings)
 File "/usr/lib64/python2.7/logging/config.py", line 794, in dictConfig
     dictConfigClass(config).configure()
 File "/usr/lib64/python2.7/logging/config.py", line 576, in configure
     '%r: %s' % (name, e))

I have this config files .ebextensions:

commands:
  00_create_dir:
    command: mkdir -p /var/log/meatme
  01_change_permissions:
    command: chmod g+s /var/log/meatme
  02_change_owner:
    command: chown -R wsgi:wsgi /var/log/meatme

and wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "meatme.settings")

application = get_wsgi_application()

When I do eb deploy it works perfect, but when i do eb clone 2 (to test scale) the new instance dont work.

When running under mod_wsgi, you should avoid setting up Python logging with a separate file. Instead, just configure it to send logging to the console stream. The messages will then be captured in the Apache error log.

Use:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
        },
    },
}

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