ubuntuサーバー16.04で私のdjango Webサイトの配備環境を設定しようとしています。サーバーに接続しようとすると、内部サーバーエラーメッセージが表示されます。Apache2、mod_wgi、django 1.9をubuntuサーバー16.04に配備する
次のように私の/var/apache2/site-available/000-default.confの内容は次のとおりです。
<VirtualHost *:80>
ServerAdmin [email protected]
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>
Djangoのウェブサイトは、中には/ var/www /の個人用サイトで、フォルダには、次のを持っています権限:以下のように
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
wsgy.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()
最後に私のsettings.pyは次のとおりです。
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 = '[email protected]'
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'
私は私はpip3ですべてのパッケージをインストールしました、私はapache2バージョンを使用しています:
Server version: Apache/2.4.18 (Ubuntu)
ととlibapache2-MOD-wsgy - PY3、須藤のapache2ctlの再起動を実行した後、私はerror.logファイルに次のエラーを取得:
[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'.
私は経由(Windowsホストマシンからサイトにアクセスしようとすると、 broswer)私はerror.logファイルの内部サーバーエラーメッセージが表示され、これらのaddictionalのログを取得:
[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'
どれ提案が高く評価されています。ありがとう。
あなたの 'Mysite'ディレクトリ(' manage.py'を含むもの)に '__init __。py'ファイルを入れてはいけません。削除してください。 – Alasdair
あなたは正しいですが、残念ながら問題の起源ではありませんでした。 –