Web 与数据

创建一个虚拟主机

在 Apache 中创建虚拟主机的配置示例:站点配置文件、DocumentRoot、ServerName、日志路径与目录权限,随后用 a2ensite 启用站点并通过 certbot 配置 HTTPS。

· 1 分钟阅读 · 难度 中级

nano /etc/apache2/sites-available/mon-site.conf

<VirtualHost *:80>

DocumentRoot "/var/www/mon-site"

ServerName mon-site.com

ServerAlias www.mon-site.com

ErrorLog ${APACHE_LOG_DIR}/mon-site.error

CustomLog ${APACHE_LOG_DIR}/mon-site.access combined

<Directory /var/www/mon-site>

Require all granted

Options FollowSymlinks MultiViews

AllowOverride All

<IfModule mod_dav.c>

Dav off

</IfModule>

SetEnv HOME /var/www/mon-site

SetEnv HTTP_HOME /var/www/mon-site

Satisfy Any

</Directory>

</VirtualHost>

请将 mon-site 替换为你的站点名称

a2ensite mon-site

如需启用 HTTPS 加密:

certbot --apache

后续内容待补充(这一部分留给学员完成)

Illustration 1 — Créer un virtualhost