¿Cómo a2ensite y a2dissite?


10

Estoy conectado a un servidor Linux. Creo que es una distribución de Red Hat.

Los comandos a2ensitey a2dissiteno están disponibles. En el /etc/httpddirectorio, no veo ninguna mención de sites-enabledo sites-available.

Estoy bastante seguro de que el sitio está ejecutando actualmente las directivas de /etc/httpd/conf.d/ssl.conf. Me gustaría hacer un a2dissite ssl, luego volver a cargar el servidor web. ¿Cómo lograr esto?

Respuestas:


24

a2ensite etc. son comandos disponibles en sistemas basados ​​en Debian y que no están disponibles en distribuciones basadas en RH.

Lo que hacen es administrar enlaces simbólicos desde partes del archivo de configuración en /etc/apache2/sites-availabley mods-availablehacia /etc/apache2/sites-enabledy así sucesivamente. Por ejemplo, si tiene un vhost definido en un archivo de configuración /etc/apache2/sites-avaible/example.com, a2ensite example.comcrearía un enlace simbólico a este archivo /etc/apache2/sites-enabledy volvería a cargar la configuración de Apache. El archivo de configuración principal de Apache contiene líneas que incluyen cada archivo /etc/apache2/sites-enabledy, por lo tanto, se incorporan a la configuración de tiempo de ejecución.

Es bastante fácil imitar esta estructura en RHEL. Añadir dos directorios en /etc/httpd/el nombre sites-enabledy sites-availabley añadir sus dominios virtuales en archivos en sites-available. Después de eso, agrega una línea

include ../sites-enabled 

a /etc/httpd/conf/httpd.conf. Ahora puede crear enlaces simbólicos sites-enabledy luego volver a cargar la configuración con service httpd reloado apachectl.


1
Ahh ya veo. Entonces, básicamente /etc/httpd/conf.d está actuando como el equivalente de sitios habilitados. Entonces, solo eliminar ssl.conf de ese directorio y reiniciar / volver a cargar httpd recogió mis cambios. Eso es genial
— John

2

Como complemento de la excelente respuesta de Sven, dos scripts que imitan el comportamiento de a2ensite y a2dissite. El ensite.sh original se puede encontrar en 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

¿Cuál debería ser el "nombre del sitio"?
— ewizard
Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.