国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Apache > 正文

Apache上部署Django步驟詳細介紹

2024-08-27 18:30:41
字體:
來源:轉載
供稿:網友

Apache上部署Django

目前,Apache和mod_python是在生產服務器上部署Django的最健壯搭配。mod_python 是一個在Apache中嵌入Python的Apache插件,它在服務器啟動時將Python代碼加載到內存中。

Django 需要Apaceh 2.x 和mod_python 3.x支持。

Apache的配置參見:http://www.djangoproject.com/r/apache/docs/

 使用mod_python部署

1.為了配置基于 mod_python 的 Django,首先要安裝有可用的 mod_python 模塊的 Apache。

2.然后應該有一個 LoadModule 指令在 Apache 配置文件中。 它看起來就像是這樣:

LoadModule python_module /usr/lib/apache2/modules/mod_python.so

3.配置Apache,用來定位請求URL到Django應用:

<VirtualHost *:80>    ServerName www.example.com    <Location "/mysite1">      SetHandler python‐program      PythonHandler django.core.handlers.modpython      SetEnv DJANGO_SETTINGS_MODULE mysite1.settings      PythonAutoReload Off      PythonDebug Off      PythonPath "['/var/www/html/mysite1'] + sys.path"      PythonInterpreter mysite1    </Location>    <Location "/mysite2">      SetHandler python‐program      PythonHandler django.core.handlers.modpython      SetEnv DJANGO_SETTINGS_MODULE mysite2.settings      PythonAutoReload Off      PythonDebug Off      PythonPath "['/var/www/html/mysite2'] + sys.path"      PythonInterpreter mysite2    </Location>    [......]</VirtualHost>

它告訴 Apache,任何在 / mysite這個路徑之后的 URL 都使用 Django 的 mod_python 來處理。 它 將DJANGO_SETTINGS_MODULE 的值傳遞過去,使得 mod_python 知道這時應該使用哪個配置。

查看 mod_python 文檔獲得詳細的指令列表。

4.重啟Apache,查看Http://www.example.com/mysite:

/etc/init.d/apache2 restart

使用mod_wsgi部署

1.下載安裝 mod_wsgi 模塊,生成mod_wsgi.so和wsgi.conf

2.在配置中加載模塊:

LoadModule python_module /usr/lib/apache2/modules/mod_wsgi.so

3.修改Apache配置文件httpd.conf

<VirtualHost *:80>    ServerName www.example    DocumentRoot /var/www/html/mysite    WSGIScriptAlias / /var/www/html/mysite/apache/django.wsgi    <Directory />        Order deny,allow        Allow from all    </Directory>    <Directory /apache>        Allow from all    </Directory></VirtualHost>

4.創建并配置wsgi的配置文件:

# filename:mysite.apache.django.wsgiimport os, sys#Calculate the path based on the location of the WSGI script.apache_configuration= os.path.dirname(__file__)project = os.path.dirname(apache_configuration)workspace = os.path.dirname(project)sys.path.append(workspace)os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'os.environ['PYTHON_EGG_CACHE'] = '/tmp'import django.core.handlers.wsgiapplication = django.core.handlers.wsgi.WSGIHandler()print >> sys.stderr, sys.path  shell>chmod a+x django.wsgi

5.修改Django項目配置文件settings.py:

DATABASES = {  'default': {    'ENGINE': 'django.db.backends.mysql',    'NAME': 'mysite',               'USER': 'admin',               'PASSWORD': 'admin123',             'HOST': '127.0.0.1',               'PORT': '3306', }}TEMPLATE_DIRS = (  '/var/www/html/mysite/templates',)

6.重啟Apache,訪問http://www.example.com/mysite

/etc/init.d/apache2 restart

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大方县| 广州市| 香格里拉县| 会泽县| 九龙坡区| 越西县| 通海县| 彭水| 阳原县| 马鞍山市| 沂南县| 老河口市| 永泰县| 浪卡子县| 永福县| 普安县| 于都县| 西宁市| 济南市| 手机| 佛山市| 广汉市| 体育| 右玉县| 自治县| 绥芬河市| 瑞丽市| 洛浦县| 班戈县| 永嘉县| 瓮安县| 阳西县| 宁远县| 徐州市| 凤冈县| 安西县| 军事| 九寨沟县| 育儿| 古蔺县| 卢氏县|