【问题标题】:What am I missing here? Apache keeps serving default page我在这里想念什么? Apache 继续提供默认页面
【发布时间】:2017-02-22 14:54:54
【问题描述】:

我已经配置了我的 Django 站点,但 Apache 继续提供默认的 apache 页面。我在这里想念什么?我的设置是 CentOS 服务器上的 Django 1.10 和 python3.5。

项目结构

/home/sbsadmin/web/sbsportal
    requirements.txt
    src
        manage.py
        media
        sbsportal
            __init__.py
            __pycache__
            settings.py
            urls.py
            wsgi.py
        static
        templates
    venv

/etc/httpd/conf.d/sbsportal.conf

LoadModule wsgi_module modules/mod_wsgi.so
<VirtualHost *:80>
  ServerAdmin admin@email.com
  ServerName sbsportal
  ServerAlias sbsportal.com
  DocumentRoot /home/sbsadmin/web/sbsportal/src/

  WSGIDaemonProcess sbsportal python-path=/home/sbsadmin/web/sbsportal/src:/home/sbsadmin/web/sbsportal/venv/lib/python3.5/site-packages
  WSGIApplicationGroup sbsportal
  WSGIScriptAlias / /home/sbsadmin/web/sbsportal/src/sbsportal/wsgi.py process-group=djangoproj

  <Directory /home/sbsadmin/web/sbsportal/src>
    Options -Indexes +FollowSymLinks +MultiViews
    AllowOverride None
    Order allow,deny
    Require all granted
  </Directory>

  <Directory /home/sbsadmin/web/sbsportal/src/sbsportal>
    <Files wsgi.py>
      Order deny,allow
      Allow from all
      Require all granted
    </Files>
  </Directory>

  Alias /static /home/sbsadmin/web/sbsportal/src/static
  <Directory /home/sbsadmin/web/sbsportal/src/static>
    Options -Indexes +FollowSymLinks +MultiViews
    AllowOverride None
    Order allow,deny
    Require all granted
  </Directory>

  Alias /static /home/sbsadmin/web/sbsportal/src/templates
  <Directory /home/sbsadmin/web/sbsportal/src/templates>
    Options -Indexes +FollowSymLinks +MultiViews
    AllowOverride None
    Order allow,deny
    Require all granted
  </Directory>

  Alias /media /home/sbsadmin/web/sbsportal/src/media
  <Directory /home/sbsadmin/web/sbsportal/src/media>
    Options -Indexes +FollowSymLinks +MultiViews
    AllowOverride None
    Order allow,deny
    Require all granted
  </Directory>

</VirtualHost>

wsgi.py

​​>
"""
WSGI config for sbsportal 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.10/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sbsportal.settings")

application = get_wsgi_application()

Settings.py

​​>
.
.
.
'DIRS': [os.path.join(BASE_DIR, 'templates'),],
.
.
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

我已经解决了几乎所有的问题。唯一不足的是,现在我看到的是403 forbidden error

【问题讨论】:

  • 您是否在 Apache 中启用了该站点?
  • @tobassist mmmmm 我不这么认为。我怎样才能做到这一点?没有什么比上面提到的先生。
  • a2ensite wsgi.conf
  • @AndreyShipilov a2ensite 在 CentOS 中不可用。
  • 那么这个ln -s /etc/httpd/sites-available/wsgi.conf /etc/httpd/conf.d/wsgi.conf

标签: django apache centos mod-wsgi wsgi


【解决方案1】:

您是否在项目目录中添加了 selinux 上下文?如果没有,请执行以下操作:

semanage fcontext -a -t httpd_sys_content_t '/home/sbsadmin/myproject/(/.*)'

restorecon -Rv /home/sbsadmin/myproject/

或者尝试禁用 selinux setenforce 0

【讨论】:

  • 天哪,这为我解决了这个问题。 :) 非常感谢。我现在可以看到 django 网站。你能解释一下它到底是什么吗?我可能无权在工作生产环境中将其关闭。
  • 不客气^^。不建议禁用 selinux,您必须将 httpd 上下文添加到您的目录项目中。看看这个serverlab.ca/tutorials/linux/web-servers-linux/…
猜你喜欢
  • 1970-01-01
  • 2010-11-22
  • 2017-06-10
  • 1970-01-01
  • 2014-10-24
  • 2015-06-21
  • 1970-01-01
  • 2011-12-02
  • 1970-01-01
相关资源
最近更新 更多