CONFIGURING APACHE

All settings are contained in the / etc / apache / folder:
The /etc/apache2/apache2.conf file is responsible for basic settings
/ etc / apache2 / conf-available / * – additional web server settings
/ etc / apache2 / mods-available / * – module settings
/ etc / apache2 / sites-available / * – virtual host settings
/etc/apache2/ports.conf – ports on which apache is running
/ etc / apache2 / envvars
As you can see there are two folders for conf, mods and site. These are available and enabled. When you enable a module or host, a symbolic link is created from the available folder to the enable folder. Therefore, it is better to make settings in the available folders. Generally speaking, one could do without these folders, take everything and dump it into one file the old fashioned way, and everything would work, but now no one does that.
First, let’s take a look at the main configuration file:
vi /etc/apache2/apache2.conf

***

Timeout – indicates how long the server will try to continue the interrupted transmission or reception of data. 160 seconds should be enough.
KeepAlive On is a very useful parameter, it allows you to transfer several files in one connection, for example, not only the html page itself, but also pictures and css files.
MaxKeepAliveRequests 100 – the maximum number of requests per connection, the more the better.
KeepAliveTimeout 5 – connection timeout, usually 5-10 seconds are enough to load the page, so you don’t need to set more, but you don’t need to break the connection before all the data is loaded either.
User, Group – user and group on behalf of which the program will work.
HostnameLookups – log domain names instead of ip addresses, it is better to disable it to speed up the work.
LogLevel – error logging level. The default is warn, but to make the logs fill up slower, just enable error
Include – all include directives are responsible for including the configuration files discussed above.

***

Directory directives are responsible for setting access rights to a particular directory in the file system. The syntax is like this:

Parameter value

AllowOverride – indicates whether to read .htaccess files from this directory, these are the same settings files and the same syntax. All – allow everything, None – do not read these files.
DocumentRoot – sets the folder from which documents should be taken to display to the user.
Options – indicates what features of the web server should be allowed in this folder. For example, All – allow everything, FollowSymLinks – follow symbolic links, Indexes – display the contents of the directory if there is no index file.
Require – Sets which users have access to this directory. Require all denied – to prohibit everyone, Require all granted – to allow everyone. you can use the user or group directive instead of all to explicitly specify the user.
Order – allows you to control access to the directory. Accepts two values: Allow, Deny – allow for all but the specified ones or Deny, Allow – deny for all but the specified ones. Now we can deny access to the directory for everyone: Deny from all, and then allow only for the application from google.com: Allow from google.com.
This file /etc/apache2/ports.conf:
It has only one directive, Listen, which tells the program which port to run on.
The last file is / etc / apache2 / envvars, which you are unlikely to use, it contains variables that can be used in other configuration files.

***

CONFIGURING AN APACHE SERVER VIA HTACCESS
Htaccess files allow you to configure your web server on Ubuntu to behave in a specific directory. All instructions specified in this file are executed as if they were wrapped in the tag if they were in the main file.
It is important to note that in order for the server to read instructions from .htaccess, the settings for this folder in the main file or in the virtual host file must not contain AllowOverride None, in order for all settings to work, you need AllowOverride All.
As for the rest, any configuration of the apache server can be performed here, from enabling modules to simply changing access to a folder. Since we have already considered all the parameters, we will just give a couple of examples:
Order Deny,Allow
Deny from all

Denies everyone access to this folder, it is important to apply for configuration folders. Most often, .htaccess is used to work with the mod_rewrite module, which allows you to modify requests on the fly:
RewriteEngine on
RewriteRule ^ product /( [^/\.†+)/?$ product.php? Id = $ 1 [L]

CONFIGURING APACHE MODULES
As I said before, Apache is a modular program, its functionality can be extended using modules. All available modules, loaders and module configuration files are located in the / etc / apache / mods-available folder. And those activated in / etc / apache / mods-enable.
But you don’t need to analyze the contents of these folders. Configuring Apache 2.4 by adding modules is done using special commands. You can view all running modules with the command:
apache2ctl -M
You can enable the module with the command:
sudo a2enmod module_name
And disable:
sudo a2dismod module_name
After enabling or disabling modules, you need to restart apache:
sudo systemctl restart apache2
As you’ve seen, it’s very easy to enable modules. Let’s enable a few modules that are required but not included by default:
sudo a2enmod expires
sudo a2enmod headers
sudo a2enmod rewrite
sudo a2enmod ssl

The expires and headers modules reduce the load on the server. They return a Not Modified header if the document hasn’t changed since the last request. The expiries module allows you to set the time for which the browser should cache the received document. Rewrite allows you to change the requested addresses on the fly, very useful when creating NC links, etc. And the last one for enabling support for SSL encryption. Don’t forget to restart apache2 after completing the settings.

Perfect cloud hosting 12$

×