All-Way Road Pit (2)--Deploy Django blog under Apache

Source: Internet
Author: User

Previous blog: All-Stack road pit use Django development blog

After the blog has been developed, many subsequent applications need to be deployed before they can be used, and this article will try to deploy the developed blog to the server.

During the development phase, the virtualenv and Python manage.py runserver were used, but it was not appropriate to deploy to the server, so I tried to deploy it to Apache.

See the relevant data find the deployment method there are two, one is Python_mod, the other is WSGI, the data said the latter more stable, so I chose to use WSGI for integration.

Install Httpd-devel, because Wsgi needs this dependency

Yum Install-y httpd-devel

Installing MOD_WSGI

Yum Install mod_wsgi.x86_64

Consulted a lot of information, stepped on a lot of pits, finally found a viable solution, now share to everyone, my server system is CENTOS7, all the software installed is the latest.

First create a configuration file under Conf.d, named Django.conf, which is automatically loaded into the httpd.conf

Because I ran a lot of projects on my server, I had to use a virtual host, edit the django.conf file

Listen 8000/var/www/django/*:8000>//var/www/django/blog/blog//var/www/ django/blog/blog><files wsgi.py>    Require all granted</files></ Directory></virtualhost>

The code for Apache added a 8000-port monitoring, and then the second line to note that can not be written in the virtual host, or will be error, and then the following is very common to write the directory into the virtual host, and then access to 8000 port

Style files are not all, because it needs to be configured in the virtual host, but each app style is written in their own configuration is very cumbersome, so use a command to extract all the styles, first, in the root directory to create a static folder, Then add a line in the settings.py, it comes with the static_url, but obviously, there is a mistake, so I choose to add one myself to go

' static/ '

Then execute the command.

Python manage.py collectstatic

Then all the static files are generated in static in the root directory, then the code is uploaded to the server and then opened again django.conf modified

Listen 8000/var/www/django/blog<virtualhost *:8000>//var/www/django/blog/blog/  /static//var/www/django/blog/static/<directory/var/www/django/blog/static>Require all granted </directory><directory/var/www/django/blog/blog><files wsgi.py>    Require All Granted</Files></Directory></VirtualHost>

Then visit the URL and find the style is OK

All-Way Road Pit (2)--Deploy Django blog under 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.