Use Mod_wsgi to connect Python to Apache server on Mac OS

Source: Internet
Author: User
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  
 
   
 
    
 
   
 
  
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.