Я пытаюсь развернуть веб-приложение Django на недавно установленном сервере centos7. для этого я использую apache2.4 с mod_wsgi.
Я застрял в обслуживании статических файлов, и, поскольку я новичок в этом, это меня так запутывает.
вот мои файлы конфигурации, если вы можете мне помочь с этим, пожалуйста.
(я удалил все, что не использую здесь, и удалил строки с комментариями)
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin admin@serv.com
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel info
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional sites-enabled/*.conf
LoadModule wsgi_module modules/mod_wsgi.so
в моей папке с поддержкой сайтов, у меня есть только один config для моего проекта
Alias /favicon.ico /var/www/cvctools/staticfiles/templates/images/favicon.ico
Alias /static/ /var/www/cvctools/staticfiles/
<VirtualHost *:80>
DocumentRoot /var/www/cvctools
ServerName proj.ma
ServerAlias www.proj.ma
ServerAdmin admin@proj.ma
<Directory /var/www/cvctools/staticfiles>
AllowOverride None
Require all granted
</Directory>
<IfModule wsgi_module>
WSGIScriptAlias / /var/www/cvctools/CapValue/wsgi.py
WSGIScriptReloading On
WSGIDaemonProcess CapValue processes=1 threads=1 maximum-requests=5000 display-name=my-wsgi
WSGIProcessGroup CapValue
WSGIPythonPath /var/www/cvctools
<Directory /var/www/cvctools/CapValue>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</IfModule>
</VirtualHost>
в папке моего проекта, расположенной в / var / www / cvctools, у меня есть это ..
./ CapValue / wsgi. py:
import django.core.handlers.wsgi
import os,sys
sys.path.append('/vat/www/cvctools')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CapValue.settings")
application = django.core.handlers.wsgi.WSGIHandler()
мои настройки статических файлов в ./CapValue/settings.py:
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(os.getcwd(), 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, 'static'),)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'compressor.finders.CompressorFinder',
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
TEMPLATES = [
{
'BACKEND' : 'django.template.backends.django.DjangoTemplates',
'DIRS' : [os.path.join(STATIC_ROOT, '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',
],
},
},
]
./CapValue/views.py:
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic.base import TemplateView
from django.utils.decorators import method_decorator
class IndexView(TemplateView):
template_name = 'index.html'
@method_decorator(ensure_csrf_cookie)
def dispatch(self, *args, **kwargs):
return super(IndexView, self).dispatch(*args, **kwargs)
./CapValue/urls.py:
#imports...
urlpatterns = [
#...
url('^.*$', IndexView.as_view(), name='index')
]
и после запуска manage.py collectstatic, в моем каталоге проекта у меня есть папка staticfiles со следующим содержимым:
/ var / www / cvctools / staticfiles /:
drwxr-xr-x. 6 admin admin 47 Mar 4 22:36 admin
drwxr-xr-x. 2 admin admin 4096 Mar 4 22:36 css
drwxr-xr-x. 5 admin admin 35 Mar 4 22:36 django_extensions
-rwxr-xr-x. 1 admin admin 0 Mar 4 22:36 human.d41d8cd98f00.txt
-rwxr-xr-x. 1 admin admin 0 Mar 4 22:36 human.txt
drwxr-xr-x. 2 admin admin 4096 Mar 4 22:36 images
drwxr-xr-x. 12 admin admin 4096 Mar 4 22:36 javascript
drwxr-xr-x. 2 admin admin 4096 Mar 4 22:36 notifications
drwxr-xr-x. 6 admin admin 47 Mar 4 22:36 rest_framework
-rwxr-xr-x. 1 admin admin 12925 Mar 4 22:36 staticfiles.json
drwxr-xr-x. 6 admin admin 4096 Mar 4 22:36 templates
, но когда я 'м пытаюсь получить доступ к приложению, в моем журнале apache я получаю эту ошибку:
[autoindex:error] [pid 3150] [client 192.168.0.126:57623] AH01276: Cannot serve directory /var/www/cvctools/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive
что именно я делаю не так?
очевидно, это как-то связано с mod_wsgi, потому что я изменил свой DcumentRoot на / var / www / cvctools / staticfiles / templates тогда я смог увидеть свою индексную страницу, но это было примерно так:
{% load staticfiles %} {% include 'stylesheets.html' %}
{% include 'navbar.html' %}
{% include 'menu.html' %}
{#
#} {# {% include 'breadcrumb.html' %}#} {#
#}
{% include 'footer.html' %}
{% include 'javascripts.html' %}
он не выбирает мои теги шаблона!