<VirtualHost *:80>
ServerAdmin samliuming@aliyun.com
DocumentRoot "/home/python_projects/Platform"
ServerName samlinux01-platform.com
ServerAlias sam-platform.com
ErrorLog "logs/platform_error.log"
CustomLog "logs/platform_access.log" common
WSGIScriptAlias / "/home/python_projects/Platform/Platform/wsgi.py"
# 一定要定义python-path到项目目录,否则会报出相关模块无法找到的错误,切记!!!
WSGIDaemonProcess samlinux01-platform.com python-path=/home/python_projects/Platform:/usr/lib64/python2.7/site-packages
WSGIProcessGroup samlinux01-platform.com
WSGIScriptReloading On
# 设定Apache访问django的项目目录
Alias /static /home/python_projects/Platform/static
Alias /media /home/python_projects/Platform/media
# 注意:将python中django admin的静态文件链接到static目录下,否则会出现登录django admin静态文件404的问题
# ln -s /usr/lib64/python2.7/site-packages/django/contrib/admin/static/admin admin
<Directory /home/python_projects/Platform/media>
AllowOverride None
Options Indexes FollowSymLinks
Require all granted
</Directory>
<Directory /home/python_projects/Platform/static>
AllowOverride None
Options Indexes FollowSymLinks
Require all granted
</Directory>
<Directory /home/python_projects/Platform/Platform>
<Files wsgi.py>
AllowOverride None
Require all granted
</Files>
</Directory>
</VirtualHost>
注意:每次编辑完成后都需要重启httpd服务使配置生效
[root@localhost ~]# httpd -t
[Thu Aug 16 20:35:06.439115 2018] [so:warn] [pid 1520] AH01574: module wsgi_module is already loaded, skipping
Syntax OK
[root@localhost ~]# systemctl restart httpd.service
编辑django中的 wsgi.py文件
"""
WSGI config for Platform 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.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Platform.settings")
application = get_wsgi_application()
# 添加项目路径到python的环境变量中
# For Apache server
import sys
project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, project_dir)
至此,大功告成,我们直接可以通过80端口访问我们的项目,虽然上面的步骤简单,但是网上查的资料并没有特别详细完整的,中间还是走了不少的弯路,所以特意将配置步骤记录下来,方便后续再次配置!