First, install MOD_WSGI 3.4:
./configure--with-apxs=/users/levin/dev/apache2.2.27/bin/apxs--with-python=/usr/bin/pythonmakemake Install
Edit httpd.conf Enable Apache to import the module mod_wsgi.so and introduce the Vhost configuration file:
LoadModule Wsgi_module modules/mod_wsgi.soinclude conf/extra/httpd-vhosts.conf
Edit extra/httpd-vhosts.conf New project and add gzip compressed text for Python output:
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. (?:p Df|doc) $ no-gzip Dont-vary addoutputfilterbytype DEFLATE text/* addoutputfilterbytype DEFLATE application/javascript Application/x-javascript application/xml addoutputfilterbytype DEFLATE application/x-httpd-php
Write a test script first app.py
def application (environ, start_response): start_response (' OK ', [(' Content-type ', ' text/html ')] return [' Hello, World ']
Or use the web.py framework:
Import Weburls = ( '/.* ', ' Hello ',) class Hello: def GET (self): return "Hello, world." application = web.application (URLs, Globals ()). Wsgifunc ()
Access in the browser: http://localhost:8001/, see Hello, world. Even if the installation is successful.
Second, the Django use may encounter the trouble resolution:
1. Modify the setting.py file:
2. Modify the project wsgi.py, this is built when the project was created, with setting.py in the same directory, I foolishly created many times, later found that the file location is wrong, tragic.
3. Modify httpd.conf in the Apache installation directory, mine is in/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 to