首页 > 代码库 > Ubantu系统下Apache2.4.7+mod_wsgi+Django环境配置

Ubantu系统下Apache2.4.7+mod_wsgi+Django环境配置

一、

安装Apache2.4:sudo apt-get install apache2

安装mod_wsgi模块:sudo apt-get install libapache2-mod-wsgi

安装Django:

sudo apt-get install python-setuptools
sudo apt-get install python-pip
sudo pip install django

进入到/etc/apache2/目录,主要配置文件为apache2.conf。

新建一个属于自己的httpd.conf,在里面进行相关配置,主要是DocumentRoot路径。主要有以下几项:

<VirtualHost *:80>  *所有IP的80端口
        ServerAdmin likunheng1@genomics.cn  *邮箱
        DocumentRoot /home/ngb/Likunheng/Website_Project/Templates/App   *网站根目录
        ErrorLog /home/ngb/Likunheng/Website_Project/Templates/error.log *网站错误记录日志
        LogLevel warn
        CustomLog /home/ngb/Likunheng/Website_Project/Templates/access.log combined *网站访问日志
        ServerSignature On


WSGIScriptAlias / /home/ngb/Likunheng/Website_Project/Model_View/WebSite/wsgi.py *Django项目中的wsgi.py (这是个大坑,2.4没有module目录,所以也不用往module加入mod_wsgi.so,而网上的大多数教程都是说把mod_wsgi.so放入module,这类说法针对2.2Apache。)

Alias /static/ /home/ngb/Likunheng/Software_folder/Django-1.6.5/django/contrib/admin/static/  *后台数据存放路径
<Directory /home/ngb/Likunheng/Software_folder/Django-1.6.5/django/contrib/admin/static/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Require all granted
</Directory>

Alias /Templates/ /home/ngb/Likunheng/Website_Project/Templates/App/  *模板存放路径
<Directory /home/ngb/Likunheng/Website_Project/Templates/App/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Require all granted
</Directory>

Alias /Website_Project/ /home/ngb/Likunheng/Website_Project/Model_View/WebSite/ *Django项目路径
<Directory /home/ngb/Likunheng/Website_Project/Model_View/WebSite/>
    #Options Indexes FollowSymLinks MultiViews
    #AllowOverride None
    #Order allow,deny
    #Allow from all
    Require all granted
</Directory>

</VirtualHost>


在配置apache2.conf中,主要有以下几项:

ServerName localhost
DirectoryIndex index.html index.htm index.php
AddDefaultCharset GB2312  *字符编码集
WSGIPythonPath /home/ngb/Likunheng/Website_Project/Model_View/  *Django项目路径(很重要的一个东西,不加这一行mod_wsgi模块会找不到你的settings.py)


# Include module configuration:
#IncludeOptional mods-enabled/*.load
#IncludeOptional mods-enabled/*.conf
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf

# Include list of ports to listen on
#Include ports.conf
Include /etc/apache2/httpd.conf  *自己新建的httpd.conf
Include /etc/apache2/ports.conf

#Include /etc/apache2/sites-enabled/*  *注释掉sites-enabled,使其中的default文件不生效
Include /etc/apache2/conf-enabled/*


至此。恭喜你。完成了LAMP最重要的也是比较难的部分配置。

从此,你可以安心的走上开发和商业之路。

完。

本文出自 “蓝鳍豚” 博客,请务必保留此出处http://likunheng.blog.51cto.com/9527645/1571850

Ubantu系统下Apache2.4.7+mod_wsgi+Django环境配置