Deploying Django on Apache

Source: Internet
Author: User
Tags apache error log

Similar to PHP, in order for Apache to be able to handle Python scripts (in fact, Apache cannot handle the script, just use other extensions to handle the script), it is necessary to install the appropriate extension module for Apache.

The original Python extension of Apache was mod_python.so this module, but later because it was not updated maintenance, so most of the use of mod_wsgi.so this module.

Another: Wsgi is a proprietary Python protocol that defines how the server communicates with the Python interpreter.

Deployment First step: Install MOD_WSGI module for Apache expansion

sudo apt-get install Libapache2-mod-wsgi

Once the installation is complete, it will automatically help you set up the necessary soft connections for Apache. (that is, there is no need to manually write a loadmodule mod_wsgi or something like that)

(Libapache2 has n more modules, should be able to install this, do not have to manually download the online)

Deploy the second step: give Apache a configuration file, specify the root directory, and explain to whom the request is handled:

The first line of Wsgiscriptalias indicates that the root directory of the Web site is visited or/home/lisong/lisongsite/django.wsgi processed. (Also note: My project in/home/lisong/lisongsite)

The second line to the future, is the normal Apache granted directory access to the thing.

Deploy step three: give Django a request to receive a file, receive a request from Apache, and distribute it to the appropriate URL for processing.

This script is broadly divided into two parts:

The first part, the project path, the application path under the project is added to the path. In fact, the first and second parts are a goal, in order for Django to find the appropriate project path, script, and so on.

The second part, indicates the path of the django_setting_module, so that the request can come in, according to the path to find the settings and do the corresponding distribution processing. All the settings for the project are settings this place.

Finally, restart Apache and the browser will be able to access the machine IP.

If there is a problem, such as newspaper 500 wrong, you can look at the Apache error log, very useful. /var/log/apache2/error.log

Deploying Django on Apache

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.