Apache2 configuration directory analysis (detailed version)

ls -al is used to view the soft link information of the software. The ones that appear -> are all soft links, followed by the real directory.

Let's look at the standard startup command for the apache2 server:

 /etc/init.d/apache2 start。

Other commands such as service apache2 start call the above command indirectly, find the script apache2 and execute it.

The /etc/init.d directory is the script of all services. You can start, close or restart the corresponding service by executing the script and adding parameters. The above is to execute the init.d file and the apache2 script below to start the apche2 server and other servers. are similar principles. The following is the content of the script file. The beginning #!/bin/sh indicates that the script file is executed with Shell--sh, and the others are ignored.


When we enter /etc/init.d/apache2 start, the system will execute the apache2 script file and call the apache2.conf configuration file.

This file is the configuration file of the apache2 server. It is in the /etc/apache2 directory.



Let's take a look at what this configuration has written:



The general situation of the /etc/apache2 directory is listed above. It roughly means that there is a configuration in it

1、apaceh2.conf、

2. The port configuration file port.conf,

3. The mods-enable folder contains files with *.load and *.conf suffixes.

4. The site-enable folder contains files with a *.conf suffix.

Actually there are other documents, it is not listed. Please see the image below, which is more direct and clearer than the image above:


Let's look at the content of apache2.conf:



The general meaning of the first sentence is to say that apache2.conf is the main configuration file. When the apache2 server starts, the scattered configuration files are combined in an Includinng way. Seeing this, you should know that this file is not a real specific configuration file, it just includes various scattered configuration files in the way of inluceding. apache2.conf is actually responsible for calling other configuration files. If you don't believe me, look at the picture below:


This is the call to include the port configuration file. How this configuration file is written, apache2.conf does not know at all, because it is not written by it.

Others are similar, such as the following is to include the configuration files conf-enable and sites-enable two configuration startup files. It also has no specific implementation part.



Let's take a look at the mods-availablel and mods-enabled folders: these two folders store some apache2 read and write operations and other modules, mods-enabled is the apache2 server startup configuration file, mods-available is the apache2 server Available configuration files, as shown below;



Did you discover anything through the above?

We found that the files in mods-enable are all shortcuts (or soft links) in mods-available.

Looking at the content of mods-available, the following figure shows the rewriter module file information under the mods-avalible folder:


We found that this is the code implementation part of the specific configuration. Therefore, if you want to add any functional module to apache2, you can directly create a shortcut from avalible to enabled. The same is true for deletion. Just delete the shortcut of a module in enabled. The actual module code is still Not gone in available.

Let's take a look at the more important configuration folders site-available and site-enabled below. These two are the configuration files for the root directory of the website .





sites-enabled is the website configuration file that apache2 is using and sites-available is the website configuration file that is available to apache2.

There is only one 000-default.conf shortcut in enabled. There are two files 000-default.conf and default-ssl.conf in availbel.

000-default.conf is the default website configuration file for websites using http protocol, and default-ss.conf is the default website configuration file for https protocol websites.

https also needs to apply for a ssl certificate, we will not talk about default-ss.conf, anyway, I can't use the https protocol.


Open the 000-defaut.con file.


ServerAdmin set an email address, if there is any problem with the server will send letters to this address, this address will appear in some pages generated by the server.

DocumentRoot is the root directory of the site so that when Apache2 starts, it scans and loads the available website configurations in /etc/apache2/sites-enabled.

When the user accesses localhost:80, Apache2 will return the index.html (or index.PHP, etc., configurable) under the default site root directory /var/www/html as a response to the request to the browser, you will appreciate It is the content of the file /var/www/html/index.html.


We now try to modify the root directory here to: /var/www, and then write an html file with the following contents:

<html>

<head>

<body>this is my website</body>

</head>

</html>



Special attention; we modified the apache2 configuration information, but it must be restarted to take effect.

service apacehe2 restart or /etc/init.d/apache2 restart.

Also remember that every time you modify the configuration, you must restart the apache2 server, otherwise the configuration will not take effect immediately.

Special attention, we visit the website like this now, it will not display the specific content. If you don't believe me, look at the picture:


We found that we saw the test.html file we wrote through the browser, but why was it not displayed.

那是因为服务默认的显示格式没有test.html。默认的显示格式在/etc/apache2/mods-available/dir.conf文件中。如下所示:默认显示的格式有:index.html index.cgi index.pl index.php index.xhtml index.htm


我们在dir.conf文件最后添加test.html格式。看看能不能显示呢:



成功了,看了这么多,你对apache2的目录是不是了解了不少呢,现在试试修改下网站根目录实践一下吧。

纸上得来终觉浅,绝知此事要躬行。




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325627755&siteId=291194637