如何a2ensite和a2dissite?


10

我已登录Linux服务器。我认为这是Red Hat发行版。

命令a2ensitea2dissite不可用。在/etc/httpd目录中,我没有看到任何提及sites-enabledsites-available

我很确定该网站当前正在执行的指令/etc/httpd/conf.d/ssl.conf。我想做一个a2dissite ssl,然后重新加载Web服务器。如何做到这一点?

Answers:


24

a2ensite 等是在基于Debian的系统中可用的命令,在基于RH的发行版中不可用。

他们做的是管理从配置文件部分的符号链接/etc/apache2/sites-available,并mods-available/etc/apache2/sites-enabled等。例如,如果您在配置文件中定义了虚拟主机/etc/apache2/sites-avaible/example.coma2ensite example.com则会在该文件中创建一个符号链接/etc/apache2/sites-enabled并重新加载apache配置。Apache主配置文件包含包含每个文件的行,/etc/apache2/sites-enabled因此它们被合并到运行时配置中。

在RHEL中模仿此结构非常容易。添加两个目录的/etc/httpd/命名sites-enabledsites-available并添加您的虚拟主机到文件中sites-available。之后,添加一行

include ../sites-enabled 

/etc/httpd/conf/httpd.conf。现在,您可以创建到的符号链接sites-enabled,然后使用service httpd reload或重新加载配置apachectl


1
啊,我明白了。因此,基本上,/ etc / httpd / conf.d相当于启用了site的角色。因此,只需从该目录中删除ssl.conf并重新启动/重新加载httpd就可以了。太酷了
约翰·

2

作为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

“站点名称”应该是什么?
ewizard
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.