Apache HTTP Server – named after the tribes of the North American Indians of Apache, is also an abbreviation of “a patchy server” – a free web server.
An example of an installation command in Ubuntu:
sudo apt-get install apache2
Example installation in CentOS:
yum install httpd
We check to open in the browser the address http://HOSTNAME
Normally, a standard inscription should appear “It works!“.
Web Storage Directory – /var/www/
Directory of configuration files – /etc/apache2/
A separate virtual host is created for each site. The standard virtual host file is located at /etc/apache2/sites-available/000-default.conf
Suppose we have an example.net domain. Create a new file in the /etc/apache2/sites-available/example.conf and prescribe the settings in it:
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org ServerName example.net ServerAlias www.example.net DocumentRoot /var/www/example.net/ <Directory /var/www/example.net> Options -Indexes AllowOverride All Order allow,deny allow from all </Directory> #You can restrict IP access to some directories, for example, the admin panel in this way: <Directory /var/www/example.net/admin> Order allow,deny allow from 127.0.0.1 192.168.0.47 172.16.30.5 </Directory> ErrorLog /var/log/example.net.error.log CustomLog /var/log/example.net.access.log combined </VirtualHost>
I’ll describe the options I mentioned above:
-Indexes – in the absence of index files index.php, index.html, etc. the contents of the directories will not be displayed.
FollowSymLinks – allows you to navigate through symbolic links.
-MultiViews – if you specify an example of a non-existent directory http://example.net/img/ the inclusion of this directive will allow you to redirect to the file http://example.net/img.php or http://example.net/img.jpg etc . if any one of them exists, such manipulations can badly affect the indexing of links by search engines, so it is better to disable this directive.
AllowOverride All – allows the use of additional configuration files. htaccess.
Next, make a link to this file in the directory /etc/apache2/sites-enabled/. You can do this with commands (the second one to delete, ending .conf is not specified):
sudo a2ensite TEXT sudo a2dissite TEXT
If you need to activate any modules, you can also do this by eg commands (the first command to enable, the second to disable):
sudo a2enmod rewrite sudo a2dismod rewrite
To activate additional configuration files:
sudo a2enconf TEXT sudo a2disconf TEXT
Now create a directory for the site and copy the files into it:
sudo mkdir /var/www/example.net
Let’s edit some web server security settings:
sudo nano /etc/apache2/conf.d/security
ServerTokens OS to: ServerTokens Prod ServerSignature On to: ServerSignature Off
Restart Apache2 for the changes to take effect:
sudo /etc/init.d/apache2 restart sudo service apache2 restart
If the server uses many IP addresses, and apache2 should not work at all, then you can specify in which it works in /etc/apche2/ports.conf, you can also change the port, for example:
Listen 22.214.171.124:80 Listen 126.96.36.199:80 Listen 188.8.131.52:8080
To work at all: