First, install MOD_WSGI 3.4:
?
1 2 3 |
./configure--with-apxs=/users/levin/dev/apache2.2.27/bin/apxs--with-python=/usr/bin/python make make install |
Edit httpd.conf make Apache import module mod_wsgi.so and introduce vhost configuration file:
?
1 2 |
LoadModule wsgi_module modules/mod_wsgi.so Include conf/extra/httpd-vhosts.conf |
Edit extra/httpd-vhosts.conf New project and increase the text for gzip compressed python output:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17-18 |
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. (?:p df|doc) $ no-gzip dont-vary addoutputfilterbytype DEFLATE text/* addoutputfilterbytype DEFLATE JavaScript application/x-javascript application/xml addoutputfilterbytype DEFLATE application/x-httpd-php </ Directory> </VirtualHost> |
Write a test script first app.py
?
1 2 3 |
def application (environ, start_response): Start_response (' OK ', [(' Content-type ', ' text/html ')] return [' Hello, World. '] |
Or use the web.py framework:
?
1 2 3 4 5 6 7 8 9 10 11 |
Import Web urls = ('/.* ', ' 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 use of Django may encounter problems to solve:
1. Modify the setting.py file:
?
1 2 3 |
DEBUG = True Template_debug = False allowed_hosts = [' localhost '] |
2. Modify the wsgi.py in the project, this is the time to build the project with the creation, with setting.py in the same directory, I foolishly created many times, and later found that the file location is not right, tragedy.
?
1 2 3 4 |
#/library/webserver/documents is the documentroot location in Apache #votebing is the project I built import sys sys.path.append ('/library/webserver /documents/votebing ') |
3. Modify the httpd.conf in the Apache installation directory, mine is in/etc/apache2/httpd.conf
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#载入mod_wsgi LoadModule wsgi_module/usr/libexec/apache2/mod_wsgi.so W sgiscriptalias/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> |