Ubuntu apache2 Wsgi Deploying Django

Source: Internet
Author: User

Deploying Django on Ubuntu is actually straightforward, and the most important problem is that the path is set correctly.

One, install Python and Django. This is simple, and Django installs it with PIP. Don't explain it.

Second, install Apache2 and WSGI.

Apt-get is used here.

sudo apt-get insall apache2

sudo apt-get install Libapache2-mod-wsgi

It is important to note that if the previous installation was configured over Apache2 and the configuration was messy and could not be repaired, it is recommended or completely uninstalled after the installation. Commands for full uninstallation:

$ sudo apt-get--purge remove Apache-common

$ sudo apt-get--purge remove apache*

After installation, go to/etc/apache2/under the mods-available and mods-enabled to see if there are wsgi.conf and wsgi.load two files.

Third, configure Apache and WSGI

(PS. Assume that you are under directory/var/www/mysite django-admin.py startproject testproject).

1. Apache Configuration:

Create a new file in/etc/apache2/site-available testdjango.conf (PS. Delete Chinese comments when writing)

<virtualhost *: the>ServerName testproject.djangoserver #ServerName这个无所谓, just map your IP address to this on the host. The simplest way to change the host is to usesudoA2dissite the-default.conf and other virtual host to disable off, only stay testdjango.conf. (PS. In site-enabled site is enable, can be viewed according to this) DocumentRoot/var/www/mysite/testproject# This is the root directory that points to the Web site<Directory/var/www/mysite/testproject>Order Allow,denyallow from all</Directory>wsgidaemonprocess. Djangoserver processes=2threads= thedisplay-name=%{group}wsgiprocessgroup testproject.djangoserver# here testproject.djangoserver corresponds to the preceding servername Wsgiscriptalias //var/www/mysite/testproject/apache/django.wsgi# (/And/var ... There is a space in the middle) that points to the root of the Web site that follows that path. The first one "/"indicates the root of the Web site when external access is available, and when there is a new requset, Apache starts parsing from here. </VirtualHost>

2, the WSGI configuration

Create a new Dir:apache under/var/www/mysite/testproject/. Create a new file Django.wsgi under./apache. (The file name corresponds to the file name in the previous Wsgiscriptalias second path)

ImportOSImportSyspath='/var/www/mysite'ifPath not inchsys.path:sys.path.insert (0,'/var/www/mysite/testproject')#temporarily join the site Engineering directory to Ubuntu system environmentos.environ['Django_settings_module'] ='testproject.settings' #Create a new environment variable django_settings_module to point to the settings.py of the website project, where#with ' testproject.settings 'Importdjango.core.handlers.wsgiapplication= Django.core.handlers.wsgi.WSGIHandler ()

After configuration is complete

sudo a2ensite testdjango.conf

sudo service apache2 Reload

Then the browser http://127.0.0.1 to see the Django initial page.

PS. If something goes wrong, be sure to look at Apache2 's err log.

Command Line input: Tail/var/log/apache2/error.log

If you encounter server 403 error, then your "/" directory may be blocked (default)
Modify the Apache2.conf file (located in/etc/apache2/)
Change the require all denied to allow by all

Ubuntu apache2 Wsgi Deploying Django

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.