作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 ubuntu 服务器 16.04 上为我的 django 网站设置部署环境。当尝试连接到服务器时,我收到内部服务器错误消息。
我的/var/apache2/site-available/000-default.conf 的内容如下:
<VirtualHost *:80>
ServerAdmin mymailaddress@pippo.com
DocumentRoot /var/www/MySite
Alias /static /var/www/MySite/static
<Directory /var/www/MySite/static>
Require all granted
</Directory>
Alias /media /var/www/MySite/media
<Directory /var/www/MySite/media>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/MySite/MySite/wsgy.py
<Directory /var/www/MySite/MySite>
<Files wsgy.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess MySite python-path=/var/www/MySite:/usr/lib/python3.5/dist-packages
WSGIProcessGroup MySite
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log
</VirtualHost>
drwxr-xr-x 10 root www-data 4096 Aug 29 17:39 MySite
total 44
drwxr-xr-x 10 root www-data 4096 Aug 29 17:39 .
drwxr-xr-x 4 root root 4096 Aug 29 17:44 ..
drwxr-xr-x 3 root www-data 4096 Aug 30 04:44 MySite
-rw-r--r-- 1 root www-data 0 Aug 29 17:39 __init__.py
-rwxr-xr-x 1 root www-data 251 Aug 29 17:39 manage.py
drwxr-xr-x 3 root www-data 4096 Aug 29 17:39 media
drwxr-xr-x 4 root www-data 4096 Aug 29 18:28 navigation
drwxr-xr-x 5 root www-data 4096 Aug 29 18:28 projects
drwxr-xr-x 4 root www-data 4096 Aug 29 18:28 public_interfaces
drwxr-xr-x 6 root www-data 4096 Aug 29 17:39 static
drwxr-xr-x 3 root www-data 4096 Aug 29 17:39 templates
drwxr-xr-x 4 root www-data 4096 Aug 29 18:28 user_extended
total 32
drwxr-xr-x 3 root www-data 4096 Aug 30 04:44 .
drwxr-xr-x 10 root www-data 4096 Aug 29 17:39 ..
-rw-r--r-- 1 root www-data 0 Aug 29 17:39 __init__.py
drwxr-xr-x 2 root www-data 4096 Aug 29 18:38 __pycache__
-rw-r--r-- 1 root www-data 4408 Aug 29 19:12 settings.py
-rw-r--r-- 1 root www-data 1440 Aug 29 17:39 urls.py
-rw-r--r-- 1 root www-data 95 Aug 29 17:39 views.py
-rw-r--r-- 1 root www-data 393 Aug 30 04:44 wsgi.py
"""
WSGI config for MySite project.
It 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
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MySite.settings")
application = get_wsgi_application()
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__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = **************
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['www.mysite.com', 'mysite.com']
# Application definition
INSTALLED_APPS = [
'crispy_forms',
'haystack',
'projects.apps.ProjectsConfig',
'navigation.apps.NavigationConfig',
'public_interfaces.apps.PublicInterfacesConfig',
'user_extended.apps.UserExtendedConfig',
'django.contrib.admin',
'django.contrib.sites',
'registration',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'MySite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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 = 'MySite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME':'mysitedb',
'USER': 'citro',
'PASSWORD': *****************,
'HOST': 'localhost',
'PORT': '',
}
}
# Password validation
# https://docs.djangoproject.com/en/1.9/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/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media')
# Email settings
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.email.com'
EMAIL_HOST_USER = 'pippo@email.com'
EMAIL_HOST_PASSWORD = *******
EMAIL_PORT = ********
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}
ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; you may, of course, use a different value.
REGISTRATION_FORM = 'user_extended.forms.MySiteRegistrationForm'
CRISPY_TEMPLATE_PACK = 'bootstrap3'
Server version: Apache/2.4.18 (Ubuntu)
[Tue Aug 30 07:11:41.452762 2016] [mpm_event:notice] [pid 4217:tid 140136362780544] AH00494: SIGHUP received. Attempting to restart AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Tue Aug 30 07:11:41.515933 2016] [wsgi:warn] [pid 4217:tid 140136362780544] mod_wsgi: Compiled for Python/3.5.1+.
[Tue Aug 30 07:11:41.515946 2016] [wsgi:warn] [pid 4217:tid 140136362780544] mod_wsgi: Runtime using Python/3.5.2.
[Tue Aug 30 07:11:41.516784 2016] [mpm_event:notice] [pid 4217:tid 140136362780544] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Tue Aug 30 07:11:41.516816 2016] [core:notice] [pid 4217:tid 140136362780544] AH00094: Command line: '/usr/sbin/apache2'
[Tue Aug 30 07:11:41.592253 2016] [wsgi:error] [pid 10223:tid 140136362780544] mod_wsgi (pid=10223): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Tue Aug 30 07:11:41.592282 2016] [wsgi:error] [pid 10223:tid 140136362780544] mod_wsgi (pid=10223): Call to 'site.addsitedir()' failed for '/usr/local/lib/python3.5/dist-packages'.
[Tue Aug 30 07:11:41.452762 2016] [mpm_event:notice] [pid 4217:tid 140136362780544] AH00494: SIGHUP received. Attempting to restart AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Tue Aug 30 07:11:41.515933 2016] [wsgi:warn] [pid 4217:tid 140136362780544] mod_wsgi: Compiled for Python/3.5.1+.
[Tue Aug 30 07:11:41.515946 2016] [wsgi:warn] [pid 4217:tid 140136362780544] mod_wsgi: Runtime using Python/3.5.2.
[Tue Aug 30 07:11:41.516784 2016] [mpm_event:notice] [pid 4217:tid 140136362780544] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Tue Aug 30 07:11:41.516816 2016] [core:notice] [pid 4217:tid 140136362780544] AH00094: Command line: '/usr/sbin/apache2'
[Tue Aug 30 07:11:41.592253 2016] [wsgi:error] [pid 10223:tid 140136362780544] mod_wsgi (pid=10223): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Tue Aug 30 07:11:41.592282 2016] [wsgi:error] [pid 10223:tid 140136362780544] mod_wsgi (pid=10223): Call to 'site.addsitedir()' failed for '/usr/local/lib/python3.5/dist-packages'.
[Tue Aug 30 07:17:54.414936 2016] [wsgi:error] [pid 10223:tid 140136256911104] mod_wsgi (pid=10223): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Tue Aug 30 07:17:54.414984 2016] [wsgi:error] [pid 10223:tid 140136256911104] mod_wsgi (pid=10223): Call to 'site.addsitedir()' failed for '/usr/local/lib/python3.5/dist-packages'.
[Tue Aug 30 07:17:55.464287 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] mod_wsgi (pid=10223): Target WSGI script '/var/www/MySite/MySite/wsgi.py' cannot be loaded as Python module.
[Tue Aug 30 07:17:55.464350 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] mod_wsgi (pid=10223): Exception occurred processing WSGI script '/var/www/MySite/MySite/wsgi.py'.
[Tue Aug 30 07:17:55.483045 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] Traceback (most recent call last):
[Tue Aug 30 07:17:55.483118 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "/var/www/MySite/MySite/wsgi.py", line 16, in <module>
[Tue Aug 30 07:17:55.483123 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] application = get_wsgi_application()
[Tue Aug 30 07:17:55.483129 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Tue Aug 30 07:17:55.483132 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] django.setup()
[Tue Aug 30 07:17:55.483141 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 17, in setup
[Tue Aug 30 07:17:55.483144 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Aug 30 07:17:55.483150 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 55, in __getattr__
[Tue Aug 30 07:17:55.483152 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] self._setup(name)
[Tue Aug 30 07:17:55.483157 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 43, in _setup
[Tue Aug 30 07:17:55.483160 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] self._wrapped = Settings(settings_module)
[Tue Aug 30 07:17:55.483164 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 99, in __init__
[Tue Aug 30 07:17:55.483167 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] mod = importlib.import_module(self.SETTINGS_MODULE)
[Tue Aug 30 07:17:55.483181 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Tue Aug 30 07:17:55.483184 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] return _bootstrap._gcd_import(name[level:], package, level)
[Tue Aug 30 07:17:55.483189 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Tue Aug 30 07:17:55.483194 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Tue Aug 30 07:17:55.483199 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Tue Aug 30 07:17:55.483203 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Tue Aug 30 07:17:55.483208 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Tue Aug 30 07:17:55.483213 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Tue Aug 30 07:17:55.483217 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Tue Aug 30 07:17:55.483237 2016] [wsgi:error] [pid 10223:tid 140136256911104] [remote 10.9.11.150:19964] ImportError: No module named 'MySite'
最佳答案
FWIW。您的日志文件与您所说的配置所说的不完全匹配。
首先,尝试删除 /usr/lib/python3.5/dist-packages
来自 python-path
选项。它不应该是必需的,添加第二条路径可能会触发 Python 3 下的问题,该问题已在一段时间前在 mod_wsgi 中修复。不幸的是,Ubuntu 在 2 年前发布了一个 mod_wsgi 版本,即使在最近的 Ubuntu 版本中也是如此。它们比最新版本落后 30 多个版本。一般建议不要使用 Ubuntu 提供的 mod_wsgi 包,自己从源代码编译 mod_wsgi。不支持 Ubuntu 提供的版本,因为它太旧了。
关于django - 在 ubuntu 服务器 16.04 上使用 Apache2、mod_wgi 和 django 1.9 部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39230359/
我正在尝试在 ubuntu 服务器 16.04 上为我的 django 网站设置部署环境。当尝试连接到服务器时,我收到内部服务器错误消息。 我的/var/apache2/site-available/
我是一名优秀的程序员,十分优秀!