Answers:
a2ensite
等是在基于Debian的系统中可用的命令,在基于RH的发行版中不可用。
他们做的是管理从配置文件部分的符号链接/etc/apache2/sites-available
,并mods-available
以/etc/apache2/sites-enabled
等。例如,如果您在配置文件中定义了虚拟主机/etc/apache2/sites-avaible/example.com
,a2ensite example.com
则会在该文件中创建一个符号链接/etc/apache2/sites-enabled
并重新加载apache配置。Apache主配置文件包含包含每个文件的行,/etc/apache2/sites-enabled
因此它们被合并到运行时配置中。
在RHEL中模仿此结构非常容易。添加两个目录的/etc/httpd/
命名sites-enabled
和sites-available
并添加您的虚拟主机到文件中sites-available
。之后,添加一行
include ../sites-enabled
到/etc/httpd/conf/httpd.conf
。现在,您可以创建到的符号链接sites-enabled
,然后使用service httpd reload
或重新加载配置apachectl
。
作为Sven出色答案的附加,提供了两个脚本,它们模仿a2ensite和a2dissite的行为。原始的ensite.sh可以在Github上找到
a2ensite.sh
#!bin/bash
# Enable a site, just like the a2ensite command.
SITES_AVAILABLE_CONFIG_DIR="/etc/httpd/sites-available";
SITES_ENABLED_CONFIG_DIR="/etc/httpd/sites-enabled";
if [ $1 ]; then
if [ -f "${SITES_ENABLED_CONFIG_DIR}/${1}" ]; then
echo "Site ${1} was already enabled!";
elif [ ! -w $SITES_ENABLED_CONFIG_DIR ]; then
echo "You don't have permission to do this. Try to run the command as root."
elif [ -f "${SITES_AVAILABLE_CONFIG_DIR}/${1}" ]; then
echo "Enabling site ${1}...";
ln -s $SITES_AVAILABLE_CONFIG_DIR/$1 $SITES_ENABLED_CONFIG_DIR/$1
echo "done!"
else
echo "Site not found!"
fi
else
echo "Please, inform the name of the site to be enabled."
fi
a2dissite.sh
#!bin/bash
# Disable a site, just like a2dissite command, from Apache2.
SITES_AVAILABLE_CONFIG_DIR="/etc/httpd/sites-available";
SITES_ENABLED_CONFIG_DIR="/etc/httpd/sites-enabled";
if [ $1 ]; then
if [ ! -f "${SITES_ENABLED_CONFIG_DIR}/${1}" ]; then
echo "Site ${1} was already disabled!";
elif [ ! -w $SITES_ENABLED_CONFIG_DIR ]; then
echo "You don't have permission to do this. Try to run the command as root."
elif [ -f "${SITES_AVAILABLE_CONFIG_DIR}/${1}" ]; then
echo "Disabling site ${1}...";
unlink $SITES_ENABLED_CONFIG_DIR/$1
echo "done!"
else
echo "Site not found!"
fi
else
echo "Please, inform the name of the site to be enabled."
fi