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

在Mac OS上使用mod_wsgi連接Python與Apache服務(wù)器

 更新時(shí)間:2015年12月24日 15:09:43   投稿:goldensun  
這篇文章主要介紹了在Mac OS上使用mod_wsgi連接Python與Apache服務(wù)器的方法,同時(shí)文中還介紹了使用Python的Django框架時(shí)mod_wsgi連接方式下可能遇到的問題的一般解決方法,需要的朋友可以參考下

一、安裝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導(dǎo)入模塊mod_wsgi.so以及引入vhost配置文件:

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

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

<VirtualHost *:8001>
  WSGIScriptAlias / /Users/levin/dev/py/webapp/app.py/
  Alias /assets /Users/levin/dev/py/webapp/static/
  AddType text/html .py 
  <Directory /Users/levin/dev/py/webapp/>
    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
  </Directory>
</VirtualHost>

先寫個(gè)測(cè)試腳本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.修改項(xiàng)目中的wsgi.py,這個(gè)是建項(xiàng)目的時(shí)候就自帶創(chuàng)建的,跟setting.py在同一目錄,我傻傻的自己創(chuàng)建好多次,后來才發(fā)現(xiàn)文件位置不對(duì),悲劇了。

#/Library/WebServer/Documents是apache中DocumentRoot位置 
#votebing是我建的項(xiàng)目 
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 
 
<Directory /Library/WebServer/Documents/votebing/> 
<Files wsgi.py> 
Order deny,allow 
Allow from all 
</Files> 
</Directory> 
Alias /media/ /Library/WebServer/Documents/votebing/media/ 
Alias /static/ /Library/WebServer/Documents/votebing/static/ 
 
<Directory /Library/WebServer/Documents/votebing/static> 
Allow from all 
</Directory> 
 
<Directory /Library/WebServer/Documents/votebing/media> 
Allow from all 
</Directory> 

相關(guān)文章

  • python logging類庫使用例子

    python logging類庫使用例子

    這篇文章主要介紹了python logging類庫使用例子,本文講解了簡單使用、logging的level、Handlers、FileHandler + StreamHandler等內(nèi)容,需要的朋友可以參考下
    2014-11-11
  • python將字母轉(zhuǎn)化為數(shù)字實(shí)例方法

    python將字母轉(zhuǎn)化為數(shù)字實(shí)例方法

    在本篇文章里小編給大家整理的是關(guān)于python如何將字母轉(zhuǎn)化為數(shù)字的相關(guān)實(shí)例內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。
    2019-10-10
  • python對(duì) MySQL 數(shù)據(jù)庫進(jìn)行增刪改查的腳本

    python對(duì) MySQL 數(shù)據(jù)庫進(jìn)行增刪改查的腳本

    這篇文章主要介紹了python對(duì) MySQL 數(shù)據(jù)庫進(jìn)行增刪改查的腳本,幫助大家更好的利用python處理數(shù)據(jù)庫,感興趣的朋友可以了解下
    2020-10-10
  • Python?ArcPy實(shí)現(xiàn)批量對(duì)大量遙感影像相減做差

    Python?ArcPy實(shí)現(xiàn)批量對(duì)大量遙感影像相減做差

    這篇文章主要為大家介紹了如何基于Python中ArcPy模塊實(shí)現(xiàn)對(duì)大量柵格遙感影像文件批量進(jìn)行相減做差,文中的示例代碼講解詳細(xì),感興趣的可以了解一下
    2023-06-06
  • 使用Python制作獲取網(wǎng)站目錄的圖形化程序

    使用Python制作獲取網(wǎng)站目錄的圖形化程序

    這篇文章主要介紹了使用Python制作獲取網(wǎng)站目錄的圖形化程序,GUI制作使用到了PyQt,需要的朋友可以參考下
    2015-05-05
  • Python +Selenium解決圖片驗(yàn)證碼登錄或注冊(cè)問題(推薦)

    Python +Selenium解決圖片驗(yàn)證碼登錄或注冊(cè)問題(推薦)

    這篇文章主要介紹了Python Selenium解決圖片驗(yàn)證碼登錄或注冊(cè)問題,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • yolov5返回坐標(biāo)的方法實(shí)例

    yolov5返回坐標(biāo)的方法實(shí)例

    這篇文章主要給大家介紹了關(guān)于yolov5返回坐標(biāo)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-03-03
  • python使用技巧-查找文件?

    python使用技巧-查找文件?

    這篇文章主要分享的是python使用技巧查找文件,下面我們就來介紹針對(duì)python查找文件的相關(guān)內(nèi)容,需要的小伙伴可以參考一下
    2022-02-02
  • 淺析python中的set類型

    淺析python中的set類型

    這篇文章主要介紹了python中的set類型,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • 使用python實(shí)現(xiàn)哈希表、字典、集合操作

    使用python實(shí)現(xiàn)哈希表、字典、集合操作

    這篇文章主要介紹了使用python實(shí)現(xiàn)哈希表、字典、集合操作,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12

最新評(píng)論