在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>
先寫個測試腳本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,這個是建項目的時候就自帶創(chuàng)建的,跟setting.py在同一目錄,我傻傻的自己創(chuàng)建好多次,后來才發(fā)現(xiàn)文件位置不對,悲劇了。
#/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 <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項目的方法
- 深入解析Python中的WSGI接口
- 在Windows服務(wù)器下用Apache和mod_wsgi配置Python應(yīng)用的教程
- 詳解Python程序與服務(wù)器連接的WSGI接口
- 使用Nginx+uWsgi實現(xiàn)Python的Django框架站點動靜分離
- 在Linux系統(tǒng)上通過uWSGI配置Nginx+Python環(huán)境的教程
- 在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程
- 解決python3中自定義wsgi函數(shù),make_server函數(shù)報錯的問題
- 詳解python使用Nginx和uWSGI來運行Python應(yīng)用
- Python模塊WSGI使用詳解
- Python Web編程之WSGI協(xié)議簡介
相關(guān)文章
深度學(xué)習(xí)的MNIST手寫數(shù)字數(shù)據(jù)集識別方式(準確率99%,附代碼)
這篇文章主要介紹了深度學(xué)習(xí)的MNIST手寫數(shù)字數(shù)據(jù)集識別方式(準確率99%,附代碼),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06
解決pip安裝第三方庫,但PyCharm中卻無法識別的問題for mac
這篇文章主要介紹了解決pip安裝第三方庫,但PyCharm中卻無法識別的問題for mac,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-09-09
python tools實現(xiàn)視頻的每一幀提取并保存
這篇文章主要為大家詳細介紹了python tools實現(xiàn)視頻的每一幀提取并保存,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-05-05
在python中利用dict轉(zhuǎn)json按輸入順序輸出內(nèi)容方式
今天小編就為大家分享一篇在python中利用dict轉(zhuǎn)json按輸入順序輸出內(nèi)容方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02
Python實現(xiàn)列表轉(zhuǎn)Excel表格的第一列
這篇文章主要為大家詳細介紹了如何將Python中的列表轉(zhuǎn)換為Excel表格的第一列,并通過案例和代碼展示具體的操作步驟,希望可以幫助大家快速掌握這一技能2024-04-04
Python實現(xiàn)繪制Matlab格式的地圖邊框的示例代碼
這篇文章主要為大家詳細介紹了如何利用Python實現(xiàn)繪制Matlab格式的地圖邊框,文中的示例代碼講解詳細,感興趣的小伙伴可以動手嘗試一下2022-09-09

