1. 程式人生 > >在apache伺服器上部署兩個django專案總結

在apache伺服器上部署兩個django專案總結

環境說明:

Windows server2003(64) + Apache2.2 + python2.7.11 + django1.11

專案路徑說明:

兩個django專案分別為aaabbb,與apache在同一個目錄Apache Software Foundation,即在Apache Software Foundation資料夾下有Apache2.2  aaa  bbb 三個資料夾,

埠監聽在http.conf檔案中設定為:

Listen 80

http.conf中設定Servername127.0.0.1

正文:

1.首先,下載pythonweb伺服器閘道器介面wsgi,

將其命名為mod_wsgi.so,並新增到Apache2.2modules目錄下

2.Apache2.2conf目錄下的httpd.conf檔案中加入以下程式碼以讓apache載入wsgi模組:

LoadModule wsgi_module modules/mod_wsgi.so

3. httpd.conf 檔案中加入以下程式碼說明python 環境路徑:

WSGIPythonPath "C:/Python27/Lib;C:/Python27/Lib/site-packages;C:/Python27/DLLs"

WSGIPythonHome "C:/Python27"

4.apache在啟動時能載入虛擬主機模組。開啟httpd.conf 檔案,找到一下兩行程式碼,將前面的#刪掉:

#LoadModule vhost_alias_module modules/mod_vhost_alias.so

#Include conf/extra/httpd-vhosts.conf  

5. httpd.conf 中新增我們django專案的目錄,到aaa 和bbb所在層級就行了:

<Directory "D:/Program Files (x86)/Apache Software Foundation">

    #

    # Possible values for the Options directive are "None", "All",

 # or any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* --- "Options All"

    # doesn't give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.2/mod/core.html#options

    # for more information.

    #

    Options Indexes FollowSymLinks

    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   Options FileInfo AuthConfig Limit

    #

    AllowOverride None

    #

    # Controls who can get stuff from this server.

    #

    Order allow,deny

    Allow from all

</Directory>

6.<IfModule alias_module>標籤內新增 :

ScriptAlias /cgi-bin/D:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin

7.修改cgi-bin目錄為:

<Directory "D:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin">

    AllowOverride None

    Options None

    Order allow,deny

    Allow from all

</Directory>

8.接下來,儲存並關閉以上我們修改的httpd.conf檔案,開啟 conf資料夾下的extra檔案,找到

httpd-vhosts.conf 檔案並開啟做修改:

<VirtualHost *:80>  

  ServerName xxx.com

ServerAlias www.xxx.com

  WSGIScriptAlias / "D:/Program Files (x86)/Apache Software Foundation/aaa/aaa/wsgi.py"

  Alias /static "D:/Program Files (x86)/Apache Software Foundation/aaa/mysite1/static"  

  <Directory "D:/Program Files (x86)/Apache Software Foundation/aaa/mysite1/static">     

    Allow from all   

  </Directory>     

  DocumentRoot "D:/Program Files (x86)/Apache Software Foundation/aaa"  

  <Directory "D:/Program Files (x86)/Apache Software Foundation/aaa">  

        Options Indexes FollowSymLinks  

        AllowOverride None  

  </Directory>  

</virtualHost>  

<VirtualHost *:80>  

  ServerName yyy.com

  ServerAlias www.yyy.com

  WSGIScriptAlias / "D:/Program Files (x86)/Apache Software Foundation/bbb/bbb/wsgi.py"

  Alias /static "D:/Program Files (x86)/Apache Software Foundation/bbb/mysite2/static"  

  <Directory "D:/Program Files (x86)/Apache Software Foundation/bbb/mysite2/static">     

    Allow from all

  </Directory>     

  DocumentRoot "D:/Program Files (x86)/Apache Software Foundation/bbb"  

  <Directory "D:/Program Files (x86)/Apache Software Foundation/bbb">  

        Options Indexes FollowSymLinks  

        AllowOverride None  

  </Directory>  

</virtualHost>  

9.最後,開啟兩個專案的wsgi.py檔案,把我們的專案加進去即可;

  import sys  

  sys.path.append('D:/Program Files (x86)/Apache Software Foundation/aaa) 

10.重啟apache即可