欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Apache,wsgi,django 程序部署配置方法詳解

 更新時間:2019年07月01日 12:05:48   作者:輕舞肥羊  
這篇文章主要介紹了Apache,wsgi,django 程序部署配置方法,結合實例形式詳細分析了Linux環(huán)境下Apache,wsgi,django程序部署配置的相關操作技巧與注意事項,需要的朋友可以參考下

本文實例講述了Apache,wsgi,django 程序部署配置方法。分享給大家供大家參考,具體如下:

前面寫過一篇文章,ngixn,uwsgi,django,python 環(huán)境配置,有興趣的朋友可以參考 nginx,django部署

后來有人在QQ上問我,用Apache 好部署嗎?我當時只在windows下用 APACHE2.3,django1.4,wsgi 部署過,還沒有在 linux 下部署。前幾天有時間,我在 centos 上測試部署了一下。也不難。唯一的差別是,在windows 下有已經(jīng)編譯好的 wsgi.so 文件,放到  apache 的 modules下,然后在 httpd.conf 中增加

LoadModule wsgi_module modules/mod_wsgi.so

但是在 linux 下,wsgi的安裝,都要在源碼編譯下安裝,而且還有幾點要注意的。下面就詳細介紹我部署的過程。

安裝python 2.7 或者你需要的版本

這個就簡單帶過了,下載安裝包之后,windows 可以直接 運行安裝包,linux 下 最好編譯安裝吧。這一步可以參考我上面提到的文章,我已經(jīng)說得比較清楚。 但我這個centos 環(huán)境,是別人已經(jīng)裝好了的,而且比較怪異,安裝在:/usr/local/activepython27 ,一般的python 安裝在:/usr/bin/python 。其實原因簡單,因為centos 自帶的python 是 2.4 的版本較低,所以重新裝了一個新版本的。

安裝wsgi

首先要在google 代碼托管處下載.https://code.google.com/p/modwsgi ,如果是windows 的,可以直接下載編譯好的文件。linux 的兄弟們,下載源碼編譯:

wget http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
tar zxvf mod_wsgi-3.4.tar.gz
cd mod_wsgi-3.4
./configure

發(fā)現(xiàn)什么了,報錯了

./configure
checking for apxs2... no
checking for apxs... no
checking Apache version... ./configure: line 1695: apxs: command not found
./configure: line 1695: apxs: command not found
./configure: line 1696: /: is a directory

報錯的原因,也很清楚。沒有 apxs.下面安裝它

yum install httpd-devel

如果是 ubuntu  可能命令為 sudo apt-get install apache2-devsudo apt-get install apache2-threaded-dev,具體的命令可以查一下.

再次編譯

[root@29 mod_wsgi-3.4]# ./configure (這里有可能要加上python路徑 --with-python=/usr/local/activepython27)
checking for apxs2... no
checking for apxs... /usr/sbin/apxs
checking Apache version... 2.2.3
checking for python... /usr/local/activepython27/bin/python
configure: creating ./config.status
config.status: creating Makefile
[root@29 mod_wsgi-3.4]#
make
make install

得到如下編譯結果:

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/lib/httpd/modules/mod_wsgi.so
[root@29 mod_wsgi-3.4]#

配置 apache2 配置文件httpd.conf .

LoadModule wsgi_module modules/mod_wsgi.so

然后啟動 apache

service httpd start

發(fā)現(xiàn)什么鳥,這是只布谷鳥,亂叫,報錯了

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site

錯誤的原因,系統(tǒng)有多個python 版本,必須指明用哪一個python .
在apache 配置文件中,繼續(xù)加入

WSGIPythonHome /usr/local/activepython27  (這是你要采用的python的路徑,一般是/usr/bin/python,我這環(huán)境別人配成這樣了)

用什么方法可以得到這個路徑呢,直接執(zhí)行python 命令就可以得到,前提是,這個python 軟連接是你用要的python, 注意一點的是,WSGIPythonHome不要配置到<VirtualHost> </VirtualHost> 之間,否則報錯

import sys
sys.prefix 

就可以得到路徑/usr/local/activepython27 。

Django應用程序相關配置

1.我的django程序部署在 /opt/www/html/djangocms/crm 這里

 

在工程的conf 目錄下加入如下兩個文件

apache_django_wsgi.conf 文件內(nèi)容如下

<VirtualHost *:80>
  ServerName 192.168.1.111
  ServerAlias 192.168.1.111
  DocumentRoot /opt/www/html/djangocms/crm
  WSGIScriptAlias / /opt/www/html/djangocms/crm/conf/django.wsgi
  <Directory "/opt/www/html/djangocms/crm">
   order allow,deny
   Allow from all
  </Directory>
  Alias /static /opt/www/html/djangocms/crm/static
  <Location "/static">
      SetHandler None
  </Location>
  <Directory "/opt/www/html/djangocms/crm/static">
    order Deny,Allow
    Allow from all
  </Directory>
</VirtualHost>

django.wsgi 文件內(nèi)容

import os
import sys
sys.path.append("/opt/www/html/djangocms")
sys.path.append("/opt/www/html/djangocms/crm")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "crm.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

最后在 apache 配置文件 httpd.conf 中加入:

Include "/opt/www/html/djangocms/crm/conf/apache_django_wsgi.conf"

重啟apache

service httpd restart

你就看到你熟悉的django應用程序了。

希望本文所述對大家基于Django框架的Python程序設計有所幫助。

相關文章

最新評論