Apache2 configuration » History » Version 1
Guanji Wang, 16/06/2017 11:37
1 | 1 | Guanji Wang | h1. Apache2 configuration |
---|---|---|---|
2 | 1 | Guanji Wang | |
3 | 1 | Guanji Wang | @date - 15/06/2017 by guanji with instruction of Hervé |
4 | 1 | Guanji Wang | |
5 | 1 | Guanji Wang | h2. A- Introduction |
6 | 1 | Guanji Wang | |
7 | 1 | Guanji Wang | 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 | Guanji Wang | |
9 | 1 | Guanji Wang | h2. B- Prerequisites |
10 | 1 | Guanji Wang | |
11 | 1 | Guanji Wang | We need to have Apache installed: |
12 | 1 | Guanji Wang | |
13 | 1 | Guanji Wang | <pre> |
14 | 1 | Guanji Wang | % sudo apt-get install apache2 |
15 | 1 | Guanji Wang | </pre> |
16 | 1 | Guanji Wang | |
17 | 1 | Guanji Wang | h3. The Apache File Hierarchy in Ubuntu |
18 | 1 | Guanji Wang | |
19 | 1 | Guanji Wang | !Selection_312.jpg! |
20 | 1 | Guanji Wang | |
21 | 1 | Guanji Wang | h4. What is the use of these configuration files? |
22 | 1 | Guanji Wang | # 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 | Guanji Wang | # 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 | Guanji Wang | # 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 | Guanji Wang | # 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 | Guanji Wang | # 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 | Guanji Wang | # 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 | Guanji Wang | |
29 | 1 | Guanji Wang | h2. C- Basic settings |
30 | 1 | Guanji Wang | |
31 | 1 | Guanji Wang | h3. 1. Configure a new virtual host or site: |
32 | 1 | Guanji Wang | |
33 | 1 | Guanji Wang | 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 | Guanji Wang | |
35 | 1 | Guanji Wang | h4. C-1.1 Copy default conf file to the same directory with our choice: |
36 | 1 | Guanji Wang | <pre> |
37 | 1 | Guanji Wang | sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/ias_new_site.conf |
38 | 1 | Guanji Wang | </pre> |
39 | 1 | Guanji Wang | |
40 | 1 | Guanji Wang | h4. C-1.2 Examples: |
41 | 1 | Guanji Wang | |
42 | 1 | Guanji Wang | default 000-default.conf: |
43 | 1 | Guanji Wang | |
44 | 1 | Guanji Wang | |
45 | 1 | Guanji Wang | <pre> |
46 | 1 | Guanji Wang | ServerAdmin webmaster@localhost |
47 | 1 | Guanji Wang | DocumentRoot /var/www/html |
48 | 1 | Guanji Wang | </pre> |
49 | 1 | Guanji Wang | |
50 | 1 | Guanji Wang | IAS idoc-medoc-test conf (There is only one instance for the server name): |
51 | 1 | Guanji Wang | |
52 | 1 | Guanji Wang | <pre> |
53 | 1 | Guanji Wang | ServerName idoc-medoc-test.ias.u-psud.fr |
54 | 1 | Guanji Wang | |
55 | 1 | Guanji Wang | ProxyRequests Off |
56 | 1 | Guanji Wang | ProxyPass / http://localhost:8184/ |
57 | 1 | Guanji Wang | ProxyPassReverse / http://localhost:8184/ |
58 | 1 | Guanji Wang | </pre> |
59 | 1 | Guanji Wang | |
60 | 1 | Guanji Wang | |
61 | 1 | Guanji Wang | |
62 | 1 | Guanji Wang | |
63 | 1 | Guanji Wang | h2. D- Enabling Sites and Modules in Apache |
64 | 1 | Guanji Wang | |
65 | 1 | Guanji Wang | 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 | Guanji Wang | |
67 | 1 | Guanji Wang | <pre> |
68 | 1 | Guanji Wang | sudo a2ensite virtual_host_file_name |
69 | 1 | Guanji Wang | </pre> |
70 | 1 | Guanji Wang | |
71 | 1 | Guanji Wang | 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 | Guanji Wang | |
73 | 1 | Guanji Wang | <pre> |
74 | 1 | Guanji Wang | sudo systemctl restart apache2.service |
75 | 1 | Guanji Wang | |
76 | 1 | Guanji Wang | </pre> |
77 | 1 | Guanji Wang | |
78 | 1 | Guanji Wang | h2. E- Apache2ctl |
79 | 1 | Guanji Wang | |
80 | 1 | Guanji Wang | h3. 1. Check the syntax - optional: |
81 | 1 | Guanji Wang | |
82 | 1 | Guanji Wang | <pre> |
83 | 1 | Guanji Wang | sudo systemctl restart apache2.service |
84 | 1 | Guanji Wang | |
85 | 1 | Guanji Wang | </pre> |
86 | 1 | Guanji Wang | |
87 | 1 | Guanji Wang | !Selection_313.jpg! |
88 | 1 | Guanji Wang | |
89 | 1 | Guanji Wang | h3. 2. What is apache2ctl? |
90 | 1 | Guanji Wang | |
91 | 1 | Guanji Wang | h4. E- 2.1 apache2ctl - Apache HTTP server control interface |
92 | 1 | Guanji Wang | |
93 | 1 | Guanji Wang | 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. |