First, the installation of HTTPD services
Apache is an Apache HTTP server in Centos7. The following explanation for httpd is Apache HTTP Server. So want to install Apache is actually to install httpd.
Httpd.x86_64:Apache HTTP Server
Installation:
# Yum Install httpd
Setting up the HTTPD service boot
[[email protected] httpd] #'systemctl enable Httpd.service'/usr/lib/systemd/system/httpd.service '/etc/ Systemd/system/multi-user.target.wants/httpd.service'
Start the httpd service
[[email protected] httpd] # /sbin/service httpd startredirecting to/bin/systemctl start httpd.service
Access IP verification, success!
Second, the configuration
HTTPD The default configuration file directory is
[[email protected] httpd] # cd/etc/httpd/ [[email protected] httpd] # lsconf conf.d CONF.MODULES.D logs modules run
The master configuration file is/etc/httpd/conf/httpd.conf.
Configure the/etc/httpd/conf.d/directory that is stored in.
1. master configuration file
Take a look at the configuration items that are useful in the main configuration file httpd.conf
#服务器根目录
ServerRoot"/etc/httpd"#端口
#Listen 12.34.56.78:80Listen 80#域名 + port to identify the server, no domain name with IP can also
#ServerName www.example.com:80#不许访问根目录
<directory/>allowoverride None Require all denied</Directory>#Document Directory
DocumentRoot"/var/www/html"#restrictions on/var/www directory Access
<directory"/var/www">allowoverride None#Allow open access:Require All granted</Directory>#restrictions on/var/www/html directory Access<directory"/var/www/html"> Options Indexes followsymlinks allowoverride NoneRequire All granted</Directory>#default encoding
Adddefaultcharset UTF-8#Enablemmap offEnablesendfile on
#include in other configuration files
Includeoptional conf.d/*.conf
2. Download Configuration Mod_wsgi
Apache APXS extension prior to installation of MOD_WSGI
Http-devel is for Apxs,yum after you can whereis Apxs to look for him, and then compile the use behind.
# Yum install-y httpd-devel
Download
[[email protected] collectedstatic] # Yum Install Mod_wsgi
Add the following configuration in httpd.conf:
LoadModule Wsgi_module modules/mod_wsgi.so
This configuration is used to connect the DJANGO.WSGI so that the project is loaded by Apache.
Configuring the Django Wsgi
Create a new Wsgi in the project directory and create a new DJANGO.WSGI with the following contents
ImportOSImportSYSImportDjango.core.handlers.wsgi fromDjango.confImportSettings#Add This file path to Sys.path in order to import settingsSys.path.insert (0, Os.path.join (os.path.dirname (Os.path.realpath (__file__)),'.. ')) os.environ['Django_settings_module'] ='lxyproject.settings'Sys.stdout=Sys.stderrDEBUG=trueapplication= Django.core.handlers.wsgi.WSGIHandler ()
When configuring WSGI,
- The project path must be configured in the system path because the settings.py configuration file is to be found through the project path. namely Sys.path.insert (0, Os.path.join (os.path.dirname (Os.path.realpath (__file__)), '... ' )).
- Django_settings_module must point to the project's settings.py file.
The HTTPD service must be restarted after modifying the configuration of the Wsgi.
3. Configuring the Django Project Virtual host
Add the configuration file lxyproject.conf in/etc/httpd/conf.d, as follows
<virtualhost *:80>//srv/lxyproject/wsgi//static//srv/lxyproject/collectedstatic/ 10.1.101.31#ServerName example.com#serveralias www.example.com< directory/srv/lxyproject/collectedstatic> Options Indexes followsymlinks allowoverride None Require All granted</Directory><Directory/srv/lxyproject/wsgi/> Require All Granted</Directory>errorlog /etc/httpd/logs/lxyproject.error.logLogLevel warn </VirtualHost>
which
Directly to Apache, this virtual host, the request/is given to WSGI processing, that is, the configuration of the project DJANGO.WSGI will be indicated.
Description Access/static/is obtained directly from the DocumentRoot without WSGI processing.
The Django project can now be accessed through the IP configured by the Apache server.
Third, resource links
How to use the Django with Mod_wsgi
The author starof, because the knowledge itself in the change, the author is also constantly learning and growth, the content of the article is not updated regularly, in order to avoid misleading readers, convenient tracing, please reprint annotated source: http://www.cnblogs.com/starof/p/4685132. HTML has a problem welcome to discuss with me, common progress.
CENTOS7 Apache httpd Installing and configuring the Django Project