Nueva instalación de CentOS 7 (Google Compute), no se pueden agregar entradas de VirtualHost a /etc/httpd/conf.d/

Nueva instalación de CentOS 7 (Google Compute), no se pueden agregar entradas de VirtualHost a /etc/httpd/conf.d/

Acabo de realizar una instalación básica y Apache 2.4 se inicia sin problemas. Estoy migrando desde un servidor antiguo que ejecuta Apache 2.2.

Cuando coloco un archivo /etc/httpd/conf.dque contiene una VirtualHostdefinición y reinicio el servidor, se bloquea al iniciar. Esta definición de VirtualHost es la que uso en mi servidor anterior.

# systemctl restart httpd.service
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
# systemctl -l status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2017-01-22 03:03:35 UTC; 10s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 20621 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 20620 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 20620 (code=exited, status=1/FAILURE)

Jan 22 03:03:35 production-frontend-0 systemd[1]: Starting The Apache HTTP Server...
Jan 22 03:03:35 production-frontend-0 systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jan 22 03:03:35 production-frontend-0 kill[20621]: kill: cannot find process ""
Jan 22 03:03:35 production-frontend-0 systemd[1]: httpd.service: control process exited, code=exited status=1
Jan 22 03:03:35 production-frontend-0 systemd[1]: Failed to start The Apache HTTP Server.
Jan 22 03:03:35 production-frontend-0 systemd[1]: Unit httpd.service entered failed state.
Jan 22 03:03:35 production-frontend-0 systemd[1]: httpd.service failed.
# 

Aquí está el contenido del archivo conf (con el nombre de dominio cambiado):

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    <Directory /home/kenny/domains/mydomain.com/html>
        Options Indexes FollowSymLinks MultiViews ExecCGI Includes
        AllowOverride All
    </Directory>
    DocumentRoot /home/kenny/domains/mydomain.com/html
    CustomLog /home/kenny/domains/mydomain.com/logs/access.log combined
    ErrorLog /home/kenny/domains/mydomain.com/logs/error.log
    ScriptAlias /cgi-bin /home/kenny/domains/mydomain.com/cgi

    RewriteEngine on

    # Does the file exist?
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^ http://mydomain.otherdomain.com [R,L]
</VirtualHost>

Revisé la sintaxis del archivo:

# httpd -t
Syntax OK
#

Si elimino el archivo y reinicio, Apache se inicia sin problemas. Me aseguré de que los permisos de mis archivos coincidan con los archivos de configuración existentes:

# ls -l
total 20
-rw-r--r--. 1 root root 2926 Nov 14 18:04 autoindex.conf
-rw-r--r--. 1 root root  366 Nov 14 18:05 README
-rw-r--r--. 1 root root 1252 Nov 14 16:53 userdir.conf
-rw-r--r--. 1 root root  674 Jan 22 03:03 vhost.mydomain.com.conf
-rw-r--r--. 1 root root  824 Nov 14 16:53 welcome.conf
#

¿Cambió algo en Apache 2.4 que entra en conflicto con mi definición de VirtualHost?

¿Existe algún tipo de medida de seguridad en una instancia estándar de Google Compute que rechaza mi configuración?

¿Existe alguna opción de configuración que modifiqué hace años en mi servidor anterior y acabo de olvidar que necesito modificar en mi instancia de Google Compute? :)

EDITAR:

Encontré esto en el registro de errores:

Permission denied: AH00649: could not open transfer log file /home/kenny/domains/mydomain.com/logs/access.log.
AH00015: Unable to open logs

Lo verifiqué httpd.confy dice que el servidor se ejecuta como Usuario: Grupo apache:apache. Entonces hice lo siguiente para asegurarme de que Apache tuviera permiso para escribir esos archivos de registro:

chgrp -R apache /home/kenny/domains
chmod g+w /home/kenny/domains/mydomain.com/logs

Aún tengo el error. Incluso lo intenté:

touch /home/kenny/domains/mydomain.com/logs/access.log
chown kenny:apache /home/kenny/domains/mydomain.com/logs/access.log
chmod g+w /home/kenny/domains/mydomain.com/logs/access.log

Todavía me da el error. Me aseguré de que la ruta del ancestro también sea ejecutable en Apache.

/home/kenny is owned by kenny:kenny and is 755
/home/kenny/domains is owned by kenny:apache and is 755
/home/kenny/domains/mydomain.com is owned by kenny:apache and is 755
/home/kenny/domains/mydomain.com/logs is owned by kenny:apache and is 775
/home/kenny/domains/mydomain.com/logs/access.log is owned by kenny:apache and is 664

Contenido del audit.log:

type=AVC msg=audit(1485115416.525:2112): avc:  denied  { open } for  pid=25759 comm="httpd" path="/home/kenny/domains/mydomain.com/logs/access.log" dev="sda1" ino=36516072 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file
type=SYSCALL msg=audit(1485115416.525:2112): arch=c000003e syscall=2 success=no exit=-13 a0=7f6620cd15a8 a1=80441 a2=1b6 a3=ffffff00 items=0 ppid=1 pid=25759 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=SERVICE_START msg=audit(1485115416.567:2113): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=httpd comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed

'

Respuesta1

Estás ejecutando CentOS 7, que tiene SELinux habilitado de forma predeterminada.

Cuando intenta iniciar Apache, intenta cargar archivos en el directorio de inicio de un usuario, lo cual no está permitido de forma predeterminada.

Puedes permitir que Apacheleerarchivos en los directorios de inicio de los usuarios configurando el valor booleano apropiado, httpd_read_user_content. Sería una mejor idea reubicar el contenido web en un lugar más apropiado, como debajo /srv/wwwo /var/www.

Sin embargo, no existe ningún booleano SELinux que permita al servidor webescribira los directorios personales de los usuarios, lo que por supuesto es intrínsecamente peligroso. Realmente deberías mover los archivos de registro a otra parte. La ubicación estándar es /var/log/httpd. Si los usuarios necesitan poder leerlos, puede establecer permisos para que lo hagan.

información relacionada