Deploy Django program on Apache

Source: Internet
Author: User
Deploy Django program on Apache

15:56:38 | category:

Python & Django | Tag: Apache
| Font size subscription

1. Apache and mod_python

(1) install Apache: http://httpd.apache.org/1). Decompress sudo tar zxvf httpd-2.2.17.tar.gz ~ /Http-2.2.172). Enter ~ /Apache directory, run sudo. /configure -- prefix =/usr/Server/apache2 -- enable-module = So sudo make (2) Installing mod_python: http://www.modpython.org/1 ). decompress the file 2 ). install Python's open source file sudo apt-Get install python-dev3), modify the connobject In the download package. the bug in C needs to modify mod_python-3.3.1/src/connobject. c! (B = apr_brigade_sentinel (B) is! (B = apr_brigade_sentinel (bb) 4), compile mod_pythoncd mod_python-3.3.1. /configure -- With-apxs =/usr/Server/apache2/bin/apxs -- With-Python =/usr/bin/python5 ). after sudo make & sudo make install is executed successfully, mod_python.so sudo make install (3) should appear in the/usr/Server/apache2/modules directory. Add mod_python.so sudo make install (3) mod_python Module 1 in Apache) modify the Apache configuration file/Server/apache2/CONF/httpd. conf first grants sudo chmod 7 httpd permissions. conf2 ). add the configuration line for loading mod_python.so: loadmodule python_module/usr/Server/apache2/modules/mod_python.so. Maxrequestsperchild 1In this way, you do not need to restart Apache for testing during the development phase. 3. Configure the root directory.

<Location "/"> # Sets http: // localhost: 8010/sethandler Python-program pythonhandler Django. core. handlers. modpython setenv django_settings_module myblog. settings # setttings pythondebug on pythonpath "['/home/zhulp/workspaces'] + sys. path "# config map target working path </location> <location"/Media/"> sethandler none </location> <locationmatch "\. (JPG | GIF | PNG) $ "> sethandler none </locationmatch>
(5) After modifying the root directory of the file, you can store your webpage in the new directory in httpd. documentRoot "/home/zhulp/workspaces" <directory "/home/zhulp/workspaces"> (6) run multiple Django programs in the same Apache instance

<Virtualhost 127.0.0.1: 8010> servername 127.0.0.1: 8010 <location "/myblog"> sethandler Python-program pythonhandler Django. core. handlers. modpython setenv django_settings_module myblog. settings pythondebug on pythonpath "['/home/zhulp/workspaces'] + sys. path "pythoninterpreter myblog </location> <location"/ad "> sethandler Python-program pythonhandler Django. core. handlers. modpython setenv django_settings_module myproject2.settings pythondebug on pythonpath "['/home/zhulp/workspaces'] + sys. path "pythoninterpreter myproject2 </location>
<Location "/Media/"> # disable mod_python sethandler none for specific parts of the site </location>
<Locationmatch "\. (JPG | GIF | PNG) $"> # block sethandler none from URLs ending with .jpg. gif. PNG </locationmatch>
</Virtualhost>

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.