如何在Debian Linux 8.3上安装Apache - 在Debian上配置Apache Web服务器
时间:2020-07-27 12:58:58 来源:igfitidea点击:
在本教程中,我们将学习如何在Debian Linux 8.3上安装和配置Apache Web服务器。
在Debian上安装Apache后,我们还将查看如何在单个服务器上配置Apache虚拟主机以托管多个。
更新APT源列表
在Debian上安装Apache之前,使用APT-Get Update命令更新APT源列表。
apt-get update
使用APT-Get安装安装Apache2
在Debian Linux中,Apache Http Server由Apache2包提供,我们可以使用apt-get install命令安装。
apt-get install apache2
启动Apache Web服务器
使用systemctl命令启动并重新启动Debian Linux 8.3上的Apache服务器
systemctl start apache2
还使用systemctl命令设置Apache以启动系统重启。
systemctl enable apache2
在Debian默认文档root for apache web服务器是/var/www/html文件夹。
如果我们希望我们可以立即将HTML文件放入/var/www/html文件夹立即托管静态。
创建Apache虚拟主机Debian 8.3
Apache Web服务器中的虚拟主机概念允许我们在同一Web服务器上托管多个。
要首先创建VirtualHost,我们需要为/etc/apache2/sites可用/目录中的创建一个配置文件。
配置文件应以.conf扩展为止。
例如,如果名称是example.com,则配置文件应该是example.conf的内容。
.conf扩展是强制性的。
touch /etc/apache2/sites-available/example.conf
然后,我们需要将名称和文档根添加到VirtualHost目录中的配置文件中,如下所示。
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example ErrorLog /var/log/apache2/example.com-error.log CustomLog /var/log/apache2/example.com-access.log combined </VirtualHost>
接下来,创建文档root/var/www /示例
mkdir -p /var/www/example chgrp www-data /var/www/example/ chmod 755 /var/www/example/
创建虚拟主机后,我们需要使用a2ensite命令启用它,后跟配置文件的名称。
a2ensite example.conf
然后,我们需要在启用后重新启动Apache Web服务器。
systemctl restart apache2
现在域名xample.com可以从/var/www /示例目录中服务。