Подключить виртуальный хост

Конфігураційні файли для віртуальних хостів зберігаються в /etc/apache2/sites-available/

Для Apache, починаючи з версії 2.4, у файла має бути розширення .conf

Приклад файлу конфігурації хоста mysite.com (файл /etc/apache2/sites-available/mysite_com.conf**):

<VirtualHost 127.0.1.2:80>
	ServerName site.com.loc
	DocumentRoot /home/olex/www/site/site.com
	<Directory /home/olex/www/site/site.com/>
		Options +Includes
		AddType text/html .htm
		AddOutputFilter INCLUDES .htm
		AllowOverride All
		Require all granted
		# see https://olexsyn.github.io/e-note/apache/cgi-utf-fix/
		PassEnv LANG en_US.UTF-8
	</Directory>

	ScriptAlias /cgi-bin/ /home/olex/www/site/cgi-bin/
	<Directory "/home/olex/www/site/cgi-bin">
		AllowOverride None
		Options +ExecCGI -MultiViews
		Require all granted
		# see https://olexsyn.github.io/e-note/apache/cgi-utf-fix/
		PassEnv LANG en_US.UTF-8
	</Directory>

	ErrorLog /home/olex/www/__logs/site/error.log
	CustomLog /home/olex/www/__logs/site/access.log combined
</VirtualHost>

Для того, щоб Apache прочитав конфігурацію, потрібно додати символічне посилання на файл конфігурації в каталозі /etc/apache2/sites-enabled/.

Зробити це можна командою a2ensite:

sudo a2ensite site_com

яка, насправді, просто створює символічне посилання: sudo ln -s /etc/apache2/sites-available/site_com.conf /etc/apache2/sites-enabled/site_com.conf (дивись код, якщо цікаво)

перевірити наявність помилок у синтаксисі:

sudo apache2ctl configtest
Syntax OK

та перезапустити http-сервер:

sudo systemctl reload apache2

Команда для відключення конфігурації віртуального хоста:

sudo a2dissite site_com

У процесі запуску сервера можемо отримати повідомлення: Could not reliably determine the server's fully qualified domain name, ... Це можна виправити так:

Could not reliably determine

Last updated