Skip to content

Instantly share code, notes, and snippets.

@instplanet
Created October 11, 2018 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save instplanet/86d7d828df6a75fed98d00efe30a670c to your computer and use it in GitHub Desktop.
Save instplanet/86d7d828df6a75fed98d00efe30a670c to your computer and use it in GitHub Desktop.
Target WSGI script '/var/www/sentinela_site/sentinela/wsgi.py' cannot be loaded as Python module
# Python Version: Python3
# Django Version: 2.1
# Server version: Apache/2.4.18 (Ubuntu)
# My requirements.txt
diff-match-patch==20121119
Django==2.1.1
django-ajax-selects==1.7.1
django-crispy-forms==1.7.2
django-filter==2.0.0
django-formtools==2.1
django-import-export==1.1.0
django-reversion==3.0.0
django-widget-tweaks==1.4.3
djangorestframework==3.8.2
et-xmlfile==1.0.1
future==0.16.0
httplib2==0.9.2
jdcal==1.4
Markdown==2.6.11
odfpy==1.3.6
openpyxl==2.5.8
Pillow==5.2.0
psycopg2-binary==2.7.5
pytz==2018.5
PyYAML==3.13
six==1.11.0
tablib==0.12.1
unicodecsv==0.14.1
uWSGI==2.0.17.1
xadmin==2.0.1
xlrd==1.1.0
xlwt==1.3.0
#Problem Description:
# I'm trying to deploy a application in django using apache and wsgi, but even after configure everything, i still receive internal server error (500)
# Full Traceback
[Wed Oct 10 23:03:01.191650 2018] [wsgi:error] [pid 4438] [remote 186.216.186.15:61224] mod_wsgi (pid=4438): Target WSGI script '/var/www/sentinela_site/sentinela/wsgi.py' cannot be loaded as Python module.
[Wed Oct 10 23:03:01.191786 2018] [wsgi:error] [pid 4438] [remote 186.216.186.15:61224] mod_wsgi (pid=4438): Exception occurred processing WSGI script '/var/www/sentinela_site/sentinela/wsgi.py'.
[Wed Oct 10 23:03:01.191875 2018] [wsgi:error] [pid 4438] [remote 186.216.186.15:61224] Traceback (most recent call last):
[Wed Oct 10 23:03:01.191903 2018] [wsgi:error] [pid 4438] [remote 186.216.186.15:61224] File "/var/www/sentinela_site/sentinela/wsgi.py", line 12, in <module>
[Wed Oct 10 23:03:01.191912 2018] [wsgi:error] [pid 4438] [remote 186.216.186.15:61224] from django.core.wsgi import get_wsgi_application
[Wed Oct 10 23:03:01.191933 2018] [wsgi:error] [pid 4438] [remote 186.216.186.15:61224] ImportError: No module named 'django'
"""
Django settings for sentinela project.
Generated by 'django-admin startproject' using Django 2.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '****'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'xadmin',
'crispy_forms',
'reversion',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'sentinela_backend.apps.SentinelabackendConfig',
'site_sentinela',
'ajax_select',
'widget_tweaks',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'sentinela.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'template')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'sentinela.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
# TESTE
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '***',
'HOST': '***',
'PORT': '***',
'USER': '***',
'PASSWORD': '***',
}
}
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': '***',
# 'USER': '***',
# 'PASSWORD': '***',
# 'HOST': '***',
# 'PORT': '***',
# }
# }
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'pt-br'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
print(PROJECT_ROOT)
STATIC_ROOT = os.path.join(PROJECT_ROOT, '/static')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "sentinela/static")
]
EMAIL_HOST = '***'
EMAIL_HOST_USER = '***'
EMAIL_HOST_PASSWORD = '***'
EMAIL_PORT = '***'
MAIL_REPLY = 'admin@user.com'
MAIL_STOCK_MANAGER = 'stock@user.com'
WSGIDaemonProcess djangowsgi.com python-path=/var/www/sentinela_site:/var/www/sentinela_site/env/lib/python3.5/site-packages
WSGIProcessGroup djangowsgi.com
<VirtualHost *:80>
ServerName graph.s3t.com.br
WSGIScriptAlias / /var/www/sentinela_site/sentinela/wsgi.py
<Directory /var/www/sentinela_site>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
Alias /static/ /var/www/sentinela_site/sentinela/static/
<Directory /var/www/sentinela_site/sentinela/static>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
"""
exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""
import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/sentinela_site')
sys.path.append('/var/www/sentinela_site/env/lib/python3.5/site-packages')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sentinela.settings")
try:
application = get_wsgi_application()
except Exception:
if 'mod_wsgi' in sys.modules:
traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
time.sleep(2.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment