Apache+Django++mod_wsgi(ubuntu下虛擬機器方式部署過程)

來源:互聯網
上載者:User

標籤:虛擬   控制   share   har   one   include   更改   ports   exe   

前幾天以源碼的方式部署了Apache+mod_wsgi+django的項目,見我的另一個篇部落格

這幾天也用apt-get方式安裝Apache的方式,安裝了部署了一次,其中有一致的地方,也有差別的地方,再此記錄一下

環境ubuntu 16.04 +apache2.4.25 +django1.8+mod_wsgi-4.5.15+python2.7

Apache、Python2.7都是以apt-get install的方式安裝的

django1.8 是pip install django==1.8的方式安裝的

mod_wsgi-4.5.15 是需要下載源碼編譯安裝

Apache源碼與apt方式安裝的區別就是目錄結構不一樣,設定檔載入方式不一樣,源碼的方式,所有的東西在一塊,設定檔就主要是httpd.conf,啟動程式就在bin下,

如

[email protected]:/usr/local/apache24$ ls
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules
[email protected]:/usr/local/apache24$
[email protected]:/usr/local/apache24$ tree -L 1
.
├── bin      ------------------程式目錄
├── build           
├── cgi-bin        
├── conf                  -------------設定檔目錄,主要是httpd.conf
├── error         
├── htdocs
├── icons
├── include
├── logs               -------------------日誌目錄
├── man
├── manual
└── modules        ------------------模組目錄

反正都統統在一塊了!

而apt方式的,就分布到各個目錄下了

[email protected]:/tmp# whereis apache2
apache2: /usr/sbin/apache2  /usr/lib/apache2  /etc/apache2  /usr/include/apache2  /usr/share/apache2  /usr/share/man/man8/apache2.8.gz
/usr/sbin/apache2 與/usr/sbin/apache2ctl 為執行檔案

[email protected]:/tmp# ls /usr/lib/apache2    為模組目錄,以後的wsgi.so就會產生到這
modules 
[email protected]:/tmp# ls /etc/apache2   ---主目錄,主要配置都在這
apache2.conf    conf-enabled  magic           mods-enabled  sites-available
conf-available  envvars       mods-available  ports.conf    sites-enabled

 ls /usr/share/apache2    一些其他的檔案在這
apache2-maintscript-helper  ask-for-passphrase  build  default-site  error  icons

還有就是項目目錄 /var/www/html   這裡面就一個index.html

日誌目錄就在/var/log/apache2/  下,訪問日誌和錯誤記錄檔都在這

第一步,將項目放到伺服器上面,我為了方便就放到/var/www/下面,我的項目是mysit

然後更改wsgi.py 檔案,需要加一個項目路徑,sys.path.append("/var/www/mysit")

第二步,更改apache設定檔

需要做2個工作,一個是安裝mod_wsgi,源碼安裝,安裝的時候要滿足安裝條件,需要apache-dev,可以參考官方安裝說明

滿足條件了就安裝就可以了,命令就是 ./coungure  make make install  這3步,安裝完後,看看/usr/lib/apache2/modules 目錄裡有了wsgi.so了吧!

然後加設定檔 /etc/apache2/mods-available目錄下建立載入模組的設定檔

 wsgi.load

#如下一行
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

然後使用a2enmod命令,就能看到wsgi模組。輸入名字後就啟用了

再修改/etc/apache2/sites-enabled/000-default.conf   (我就用這個預設的了,也可以自己建立一個,格式一樣就可以了)

加入

DocumentRoot /var/www/mysit
WSGIScriptAlias / /var/www/mysit/mysit/wsgi.py

 Alias /static /var/www/mysit/static    (如果你還有音、視頻的,請再加相關的目錄)

<Directory /mysit/>
Options Indexes FollowSymLinks ExecCGI
AllowOverride none
Require all granted
  <Files wsgi.py>
    Require all granted
  </Files>
</Directory>
<Directory /static/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
  <Files *.jpg>
    Require all granted
  </Files>
</Directory>
<Directory /static/style/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
  <Files pkq.gif>
  Require all granted
  </Files>
</Directory>

這裡就加一些目錄存取權限

然後用a2ensite 命令,啟用 000-。。。。。。這個site就行了

然後將80連接埠的存取權限開開,那麼啟動apache服務後,訪問就可以了!

envvars 配置系統內容變數的相關參數

 

 

目前我存在的問題如下:

admin頁面登入退出等寫資料庫操作,系統會報異常,網上米有找到將admin發布的文章

setting 配置debug=false ,外部存取不了!

apache服務日誌每天早上6:25:01時會將日誌壓縮打包,碰巧的是Apache服務在這時會做一個重啟,但是哪裡控制打包日誌的,我沒找到,也不確定重啟是不是系統做的

以上問題如果有高手知道,望指點一下,謝謝

我的項目有半年時間,網站是http://60.205.221.253/  歡迎訪問

 

Apache+Django++mod_wsgi(ubuntu下虛擬機器方式部署過程)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.