Apache installation of Linux (Ubuntu 18) (5)

Installation and introduction of Linux Apache2

1. Installation of Apache2

1、更新apt源
sudo apt-get update
2、安装apache2
sudo apt-get install apache2

By default apache2 is installed in the /etc/apache2 folder

The directory structure is as follows:

Insert picture description here

A few simple commands of apache2:

Start, stop, restart, status:

sudo /etc/init.d/apache2 [ start | stop | restart | status ]
service apache2 [ start | stop | restart | status ]

For example: start and view status

sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 status

2. Introduction to Apache2 configuration

You can check the official website: http://httpd.apache.org/

1、apache2.conf

​ When the apache2 server starts, the scattered configuration files are combined together in Including. This file is not a real specific configuration file, it just includes the scattered configuration files in an inluceding way.

This file probably configures these things:

1、apaceh2.conf

2、端口配置文件port.conf

3、mods-enable文件夹,这个文件夹下都是*.load和*.conf后缀的文件

4、site-enable、conf-enabled文件夹,这两个文件夹下都是*.conf后缀的文件

code show as below:

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

2 、 envvars

This file is the parameter configuration file of the apache program, including the log path and the user name used by the program.

The default user and group is: www-data

**Default log location: /var/log/apache2/** There are error log error.log and access log access.log under /var/log/apache2/**. These configurations will be exported, and service apache2 will source the envvars file before running. If you manually run apache2, you should source it yourself, otherwise it will report that some parameters are not set.

code show as below:

unset HOME
# for supporting multiple apache2 instances
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
        SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
else
        SUFFIX=
fi
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
# temporary state file location. This might be changed to /run in Wheezy+1
export APACHE_PID_FILE=/var/run/apache2$SUFFIX/apache2.pid
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
# Only /var/log/apache2 is handled by /etc/logrotate.d/apache2.
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX
## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:

#. /etc/default/locale
export LANG

3 、 port.conf

This file is always included in the main configuration file (apache2.conf). It is used to determine the listening port for incoming connections. The default is 80. We generally reconfigure a new port.

The default monitoring is port 80, the code is as follows:

Listen 80
<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

4、mods-available、mods-enabled

These two folders store some apache2 read-write operations and other modules. mods-enabled is the startup configuration file of the apache2 server, and mods-available is the configuration file that the apache2 server can use.

mods-enabled file:

Insert picture description here

mods-available file:

Insert picture description here

We can see: mods-enable the files inside are shortcuts mods-available (or is called a soft link)

​ So, if you want to add any functional module to apache2, just 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 Did not disappear in available.

5、sites-available、sites-enabled

1. The sites-enabled file:

Insert picture description here

2、sites-available文件:

Insert picture description here

You can see: the files in sites-enable are all shortcuts in sites-available (or called soft links)

There are only two files, namely 000-default.con and default-ss.conf

  • 000-default.conf is the default website configuration file for websites using the http protocol
  • default-ss.conf is the default website configuration file used by https protocol websites

000-defaut.conf file:

The default port 80 is configured here. If the default port is modified in port.conf, then the port 80 here must be modified accordingly

ServerAdmin: Set an email address. If the server has any problems, mail will be sent to this address. This address will appear in some pages generated by the server.

**DocumentRoot:** is the root directory of this site, the default web directory: /var/www/html. In this way, when Apache2 starts, it will scan and load the available website configurations in /etc/apache2/sites-enabled.

<VirtualHost *:80
 
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
    
    	# 日志文件,APACHE_LOG_DIR是在envvars 配置的
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    

</VirtualHost>

5、conf-available、conf-enabled

These two directories are related to the configuration of some servers

1. conf-available file:

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_42272869/article/details/112984024