在Mac OS上使用mod_wsgi連接Python與Apache服務(wù)器
一、安裝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
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>
- 詳解使用Nginx和uWSGI配置Python的web項(xiàng)目的方法
- 深入解析Python中的WSGI接口
- 在Windows服務(wù)器下用Apache和mod_wsgi配置Python應(yīng)用的教程
- 詳解Python程序與服務(wù)器連接的WSGI接口
- 使用Nginx+uWsgi實(shí)現(xiàn)Python的Django框架站點(diǎn)動(dòng)靜分離
- 在Linux系統(tǒng)上通過uWSGI配置Nginx+Python環(huán)境的教程
- 在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程
- 解決python3中自定義wsgi函數(shù),make_server函數(shù)報(bào)錯(cuò)的問題
- 詳解python使用Nginx和uWSGI來運(yùn)行Python應(yīng)用
- Python模塊WSGI使用詳解
- Python Web編程之WSGI協(xié)議簡介
相關(guān)文章
python將字母轉(zhuǎn)化為數(shù)字實(shí)例方法
在本篇文章里小編給大家整理的是關(guān)于python如何將字母轉(zhuǎn)化為數(shù)字的相關(guān)實(shí)例內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。2019-10-10python對(duì) MySQL 數(shù)據(jù)庫進(jìn)行增刪改查的腳本
這篇文章主要介紹了python對(duì) MySQL 數(shù)據(jù)庫進(jìn)行增刪改查的腳本,幫助大家更好的利用python處理數(shù)據(jù)庫,感興趣的朋友可以了解下2020-10-10Python?ArcPy實(shí)現(xiàn)批量對(duì)大量遙感影像相減做差
這篇文章主要為大家介紹了如何基于Python中ArcPy模塊實(shí)現(xiàn)對(duì)大量柵格遙感影像文件批量進(jìn)行相減做差,文中的示例代碼講解詳細(xì),感興趣的可以了解一下2023-06-06Python +Selenium解決圖片驗(yàn)證碼登錄或注冊(cè)問題(推薦)
這篇文章主要介紹了Python Selenium解決圖片驗(yàn)證碼登錄或注冊(cè)問題,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-02-02使用python實(shí)現(xiàn)哈希表、字典、集合操作
這篇文章主要介紹了使用python實(shí)現(xiàn)哈希表、字典、集合操作,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12