Ubantu系統下Apache2.4.7+mod_wsgi+Django環境配置

來源:互聯網
上載者:User

標籤:ubuntu   apache   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-setuptoolssudo apt-get install python-pip
sudo pip install django

進入到/etc/apache2/目錄,主要設定檔為apache2.conf。

建立一個屬於自己的httpd.conf,在裡面進行相關配置,主要是DocumentRoot路徑。主要有以下幾項:

<VirtualHost *:80>  *所有IP的80連接埠
        ServerAdmin [email protected]  *郵箱
        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環境配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.