Project

General

Profile

Apache2 configuration » History » Version 2

Anonymous, 16/06/2017 11:41

1 1 Anonymous
h1. Apache2 configuration
2 1 Anonymous
3 1 Anonymous
@date - 15/06/2017 by guanji with instruction of Hervé
4 1 Anonymous
5 1 Anonymous
h2. A- Introduction
6 1 Anonymous
7 1 Anonymous
The Apache web server is the most popular way of serving web content on the internet. Apache breaks its functionality and components into individual units that can be customized and configured independently. The basic unit that describes an individual site or domain is called a *virtual host*.
8 1 Anonymous
9 1 Anonymous
h2. B- Prerequisites
10 1 Anonymous
11 1 Anonymous
We need to have Apache installed: 
12 1 Anonymous
13 1 Anonymous
<pre>
14 1 Anonymous
% sudo apt-get install apache2
15 1 Anonymous
</pre>
16 1 Anonymous
17 1 Anonymous
h3. The Apache File Hierarchy in Ubuntu
18 1 Anonymous
19 1 Anonymous
!Selection_312.jpg!
20 1 Anonymous
21 1 Anonymous
h4. What is the use of these configuration files? 
22 1 Anonymous
# apache2.conf: This is the main configuration file for the server. Almost all configuration can be done from within this file, although it is recommended to use separate, designated files for simplicity. This file will configure defaults and be the central point of access for the server to read configuration details.
23 1 Anonymous
# ports.conf: This file is used to specify the ports that virtual hosts we should listen on. In IAS, for idoc-medoc (-test), we use the default number - 80.
24 1 Anonymous
# conf.d/: This directory is used for controlling specific aspects of the Apache configuration. For example, it is often used to define SSL configuration and default security choices.
25 1 Anonymous
# sites-available/: This directory contains all of the virtual host files that define different websites. These will establish which content gets served for which requests. These are available configurations, not active configurations.
26 1 Anonymous
# sites-enabled/: This directory establishes which virtual host definitions are actually being used. Usually, this directory consists of symbolic links to files defined in the "sites-available" directory.
27 1 Anonymous
# mods-[enabled,available]/: These directories are similar in function to the sites directories, but they define modules that can be optionally loaded instead.
28 1 Anonymous
29 1 Anonymous
h2. C- Basic settings
30 1 Anonymous
31 1 Anonymous
h3. 1. Configure a new virtual host or site: 
32 1 Anonymous
33 1 Anonymous
h4. the DocumentRoot directive specifies where Apache2 should look for the files that make up the site. The default value is /var/www/Html, as specified in /etc/apache2/sites-available/000-default.conf. If desired, change this value in our site's virtual host file, and remember to create that directory if necessary!
34 1 Anonymous
35 1 Anonymous
h4. C-1.1 Copy default conf file to the same directory with our choice:
36 1 Anonymous
<pre>
37 1 Anonymous
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/ias_new_site.conf
38 1 Anonymous
</pre>
39 1 Anonymous
40 1 Anonymous
h4. C-1.2 Examples:
41 1 Anonymous
42 1 Anonymous
default 000-default.conf:
43 1 Anonymous
44 1 Anonymous
45 1 Anonymous
<pre>
46 1 Anonymous
        ServerAdmin webmaster@localhost
47 1 Anonymous
        DocumentRoot /var/www/html
48 1 Anonymous
</pre>
49 1 Anonymous
50 1 Anonymous
IAS idoc-medoc-test conf (There is only one instance for the server name):
51 1 Anonymous
52 1 Anonymous
<pre>
53 1 Anonymous
        ServerName idoc-medoc-test.ias.u-psud.fr
54 1 Anonymous
55 1 Anonymous
        ProxyRequests Off
56 1 Anonymous
        ProxyPass / http://localhost:8184/
57 1 Anonymous
        ProxyPassReverse / http://localhost:8184/
58 1 Anonymous
</pre>
59 1 Anonymous
60 1 Anonymous
61 1 Anonymous
62 1 Anonymous
63 1 Anonymous
h2. D- Enabling Sites and Modules in Apache
64 1 Anonymous
65 1 Anonymous
h3. 1. To automatically create a symbolic link in the "sites-enabled" directory to an existing file in the "sites-available" directory, issue the following command:
66 1 Anonymous
67 1 Anonymous
<pre>
68 1 Anonymous
sudo a2ensite virtual_host_file_name
69 1 Anonymous
</pre>
70 1 Anonymous
71 1 Anonymous
h3. 2. After enabling a site, execute the following command to tell Apache to re-read its configuration files, allowing the change to propagate:
72 1 Anonymous
73 1 Anonymous
<pre>
74 1 Anonymous
sudo systemctl restart apache2.service
75 1 Anonymous
76 1 Anonymous
</pre>
77 1 Anonymous
78 1 Anonymous
h2. E- Apache2ctl
79 1 Anonymous
80 1 Anonymous
h3.  1. Check the syntax - optional:
81 1 Anonymous
82 1 Anonymous
<pre>
83 2 Anonymous
sudo apachectl -t
84 1 Anonymous
85 1 Anonymous
</pre>
86 1 Anonymous
87 1 Anonymous
!Selection_313.jpg!
88 1 Anonymous
89 1 Anonymous
h3. 2. What is apache2ctl?
90 1 Anonymous
91 1 Anonymous
h4. E- 2.1   apache2ctl - Apache HTTP server control interface  
92 1 Anonymous
93 1 Anonymous
h4. E- 2.2   apache2ctl is a front end to the Apache HyperText Transfer Protocol (HTTP) server. It is designed to help the administrator control the functioning of the Apache apache2 daemon.