设为首页 加入收藏

TOP

Linux下配置Django_Apache_Mysql环境(CentOS 7.5)(三)
2019-09-01 23:02:21 】 浏览:37
Tags:Linux 配置 Django_Apache_Mysql 环境 CentOS 7.5
<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端口访问我们的项目,虽然上面的步骤简单,但是网上查的资料并没有特别详细完整的,中间还是走了不少的弯路,所以特意将配置步骤记录下来,方便后续再次配置!

 

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇VMware虚拟机安装CentOS7【转】-.. 下一篇linux-shell编程基础

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目