Python Django-在ubuntu服务器上部署后,浏览器上没有显示
我已经使用apache2和mod wsgi在个人ubuntu服务器上部署了我的django项目。但是,我无法在浏览器上显示任何内容。它只在页面的一角显示“错误”。如果我做错了什么,请提出建议 My settings.py:Python Django-在ubuntu服务器上部署后,浏览器上没有显示,python,apache,ubuntu,mod-wsgi,django-deployment,Python,Apache,Ubuntu,Mod Wsgi,Django Deployment,我已经使用apache2和mod wsgi在个人ubuntu服务器上部署了我的django项目。但是,我无法在浏览器上显示任何内容。它只在页面的一角显示“错误”。如果我做错了什么,请提出建议 My 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.abspa
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__)))
SECRET_KEY = 'blah blah blah'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
ADMINS = (
'surajitmishra@gmail.com',
)
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mod_wsgi.server',
'publications',
'....',
'crispy_forms',
'widget_tweaks',
]
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
},
}
SITE_ID = 1
CRISPY_TEMPLATE_PACK = 'bootstrap3'
AUTH_USER_MODEL = 'user_profile.MyUser'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # During development only
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 = 'pubnet.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',
],
},
},
]
REDIS_HOST = 'localhost'
REDIS_PORT = 6379
REDIS_DB = 0
WSGI_APPLICATION = 'pubnet.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'pubnet',
'USER': 'root',
'PASSWORD': 'password',
'HOST': '127.0.0.1', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
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',
},
]
IMAGE_TYPES = ['application/pdf; charset=binary',
'text/plain;',
'text/csv;', ]
# Internationalization
# https://docs.djangoproject.com/en/1.11/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.11/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static_root')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static', 'static_dirs'),
)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
My URL.py:
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.views.generic.base import TemplateView
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views
from django_filters.views import FilterView
from publications.filter import UserFilter
admin.autodiscover()
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('publications.urls', namespace='publication')),
......
url('^', include('django.contrib.auth.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
我的出版物/url.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^pubnet/$', views.post_list, name='post_list'),
.....
]
/etc/apache2/sites available/pubnet.conf:
<VirtualHost *:80>
ServerName pubnet.com
ServerAlias www.pubnet.com
ServerAdmin root
DocumentRoot /var/www/pubnet
WSGIScriptAlias / /var/www/pubnet/pubnet/wsgi.py
<Directory "/var/www/pubnet/pubnet/">
Require all denied
</Directory>
<Directory "/var/www/pubnet/pubnet">
<Files wsgi.py>
Require all denied
</Files>
</Directory>
ErrorLog /var/www/logs/error.log
CustomLog /var/www/logs/custom.log combined
Alias /media/ /var/www/pubnet/media/
Alias /static/ /var/www/pubnet/static/
<Directory /var/www/pubnet/static>
Require all denied
</Directory>
<Directory /var/www/pubnet/media>
Require all denied
</Directory>
</VirtualHost>
/var/log/apache2/error.log:
[Thu Jul 27 15:23:32.498309 2017] [mpm_prefork:notice] [pid 30495] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 mod_wsgi/3.4 Python/2.7.6 mod_perl/2.0.8 Perl/v5.18.2 configured -- resuming normal operations
[Thu Jul 27 15:23:32.498403 2017] [core:notice] [pid 30495] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jul 27 16:30:29.106801 2017] [mpm_prefork:notice] [pid 30495] AH00169: caught SIGTERM, shutting down
[Thu Jul 27 16:33:32.680148 2017] [mpm_prefork:notice] [pid 21253] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 mod_wsgi/3.4 Python/2.7.6 mod_perl/2.0.8 Perl/v5.18.2 configured -- resuming normal operations
[Thu Jul 27 16:33:32.680237 2017] [core:notice] [pid 21253] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jul 27 17:19:21.703341 2017] [mpm_prefork:notice] [pid 21253] AH00169: caught SIGTERM, shutting down
我暂时保留了对pubnet目录的“777”权限
请提供帮助。尝试使用debug=true运行,并检查是否显示了任何正确的错误消息。使用debug=true和allowed\u host=[],没有运气。localhost或127.0.0.1或pubnet.com,所有这些都让我进入apache2页面。而localhost/admin在浏览器上显示“未指定输入文件”。浏览器上显示的确切错误消息是什么?Apache错误日志中的错误消息是什么?您也不应该在公共站点上发布您的
密钥。现在就改变它,然后去研究它的用途以及为什么不应该公开它。:-)@格雷厄姆·邓普尔顿,谢谢你提供的信息。我改了。在我之前的评论中,我已经在浏览器上发布了确切的错误消息。我已将Apache错误日志中的错误消息包含在我的帖子中。请尝试使用debug=true运行,并检查是否显示了任何正确的错误消息。使用debug=true和allowed_host=[]编辑错误消息,运气不好。localhost或127.0.0.1或pubnet.com,所有这些都让我进入apache2页面。而localhost/admin在浏览器上显示“未指定输入文件”。浏览器上显示的确切错误消息是什么?Apache错误日志中的错误消息是什么?您也不应该在公共站点上发布您的密钥。现在就改变它,然后去研究它的用途以及为什么不应该公开它。:-)@格雷厄姆·邓普尔顿,谢谢你提供的信息。我改了。在我之前的评论中,我已经在浏览器上发布了确切的错误消息。我已经在帖子中包含了来自Apache错误日志的错误消息。
[Thu Jul 27 15:23:32.498309 2017] [mpm_prefork:notice] [pid 30495] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 mod_wsgi/3.4 Python/2.7.6 mod_perl/2.0.8 Perl/v5.18.2 configured -- resuming normal operations
[Thu Jul 27 15:23:32.498403 2017] [core:notice] [pid 30495] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jul 27 16:30:29.106801 2017] [mpm_prefork:notice] [pid 30495] AH00169: caught SIGTERM, shutting down
[Thu Jul 27 16:33:32.680148 2017] [mpm_prefork:notice] [pid 21253] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.21 mod_wsgi/3.4 Python/2.7.6 mod_perl/2.0.8 Perl/v5.18.2 configured -- resuming normal operations
[Thu Jul 27 16:33:32.680237 2017] [core:notice] [pid 21253] AH00094: Command line: '/usr/sbin/apache2'
[Thu Jul 27 17:19:21.703341 2017] [mpm_prefork:notice] [pid 21253] AH00169: caught SIGTERM, shutting down