日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

在Mac OS上使用mod_wsgi連接Python與Apache服務器

系統 1774 0

一、安裝mod_wsgi 3.4:

            
./configure --with-apxs=/Users/levin/dev/apache2.2.27/bin/apxs --with-python=/usr/bin/python
make
make install

          

編輯httpd.conf使Apache導入模塊mod_wsgi.so以及引入vhost配置文件:

            
LoadModule wsgi_module modules/mod_wsgi.so
Include conf/extra/httpd-vhosts.conf


          
編輯extra/httpd-vhosts.conf新建項目并增加gzip壓縮python輸出的文本:
            
Listen 8001


            
              
  WSGIScriptAlias / /Users/levin/dev/py/webapp/app.py/
  Alias /assets /Users/levin/dev/py/webapp/static/
  AddType text/html .py 
  
              
              
    Order deny,allow
    Allow from all 
    SetOutputFilter DEFLATE       #開啟gzip
    SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary      #圖片不開啟gzip
    SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|rar)$ no-gzip dont-vary   #壓縮包不開啟gzip
    SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no-gzip dont-vary
    AddOutputFilterByType DEFLATE text/*
    AddOutputFilterByType DEFLATE application/javascript application/x-javascript application/xml
    AddOutputFilterByType DEFLATE application/x-httpd-php
  

            
          

先寫個測試腳本app.py

            
def application(environ, start_response):
  start_response('200 OK', [('Content-Type', 'text/html')])
  return ['Hello, world.']

          

或者使用web.py框架:

            
import web

urls = (
  '/.*', 'hello',
)

class hello:
  def GET(self):
    return "Hello, world."

application = web.application(urls, globals()).wsgifunc()


          

在瀏覽器中訪問: http://localhost:8001/,看到Hello, world.就算安裝成功了。

二、Django使用中可能遇到的麻煩解決:
1.修改setting.py文件:

            
DEBUG = True 
TEMPLATE_DEBUG = False 
ALLOWED_HOSTS = ['localhost'] 

          

2.修改項目中的wsgi.py,這個是建項目的時候就自帶創建的,跟setting.py在同一目錄,我傻傻的自己創建好多次,后來才發現文件位置不對,悲劇了。

            
#/Library/WebServer/Documents是apache中DocumentRoot位置 
#votebing是我建的項目 
import sys 
sys.path.append('/Library/WebServer/Documents/votebing') 

          

3.修改apache安裝目錄中的httpd.conf,我的是在/etc/apache2/httpd.conf

            
#載入mod_wsgi 
LoadModule wsgi_module /usr/libexec/apache2/mod_wsgi.so 

WSGIScriptAlias /votebing /Library/WebServer/Documents/votebing/votebing/wsgi.py 
WSGIPythonPath /Library/WebServer/Documents 
 

            
            
               
Order deny,allow 
Allow from all 

            
             
 
Alias /media/ /Library/WebServer/Documents/votebing/media/ 
Alias /static/ /Library/WebServer/Documents/votebing/static/ 
 

            
               
Allow from all 

            
            
               
Allow from all 

            
          


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 青神县| 广宁县| 麻栗坡县| 葵青区| 北票市| 闽侯县| 怀化市| 桓台县| 山西省| 南投县| 湾仔区| 峡江县| 紫云| 封丘县| 清河县| 蓬安县| 磴口县| 安岳县| 门头沟区| 义马市| 隆回县| 镇坪县| 疏附县| 巴彦县| 明水县| 台前县| 舞阳县| 怀远县| 珠海市| 永善县| 师宗县| 柳州市| 偃师市| 丹江口市| 遂昌县| 东光县| 东方市| 铁岭县| 伊宁市| 临澧县| 长子县|