webdevops / Dockerfile

:package: Dockerfiles from WebDevOps for PHP, Apache and Nginx
https://webdevops.io/projects/dockerfiles/
MIT License
1.67k stars 493 forks source link

How to add more vhost in one server Apache? #216

Closed innovaweb-dev closed 6 years ago

innovaweb-dev commented 6 years ago

Hi all and thanks you for your assitance. I create my first docker-compose.yml and it works correctly with image webdevops/php-apache:debian-8-php7. But now I need to add a lot vhost in my apache server and Docker displays this message AH00526: Syntax error on line 1 of /opt/docker/etc/httpd/vhost.common.d/vhost.conf: <VirtualHost> cannot occur within <VirtualHost> section

Do you know why ? my docker-compose.yml

web:
    image: webdevops/php-apache:debian-8-php7
    volumes:
        - d:/dev/www:/var/www/html
        - d:/dev/vhost.conf:/opt/docker/etc/httpd/vhost.common.d/vhost.conf
    ports:
        - "80:80"
    environment:
        - WEB_DOCUMENT_ROOT=/var/www/html
        - PHP_DISPLAY_ERRORS=1

my vhost.conf

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
    ServerName project1.dev
    DocumentRoot /var/www/html/project1/public
</VirtualHost>
<VirtualHost *:80>
    ServerName project2.dev
    DocumentRoot /var/www/html/project2/public
</VirtualHost>

And if you need the guide of the image that I use: http://dockerfile.readthedocs.io/en/latest/content/DockerImages/dockerfiles/php-apache-dev.html#apache-layout

Thanks all for your help

PanadeEdu commented 6 years ago

You are actualy writing to the wrong file. vhost.common.d/vhost.conf is only used in the vhost.conf The used vhost is: /opt/docker/etc/httpd/vhost.conf

But simply copying it there will not cut it completely. Here is the actual vhost.conf inside the container:

#######################################
# Vhost
#######################################

<VirtualHost *:80>
  ServerName docker.vm
  ServerAlias *.vm
  DocumentRoot "/var/www/html"

  UseCanonicalName Off

  <IfVersion < 2.4>
    Include /opt/docker/etc/httpd/vhost.common.d/*.conf
  </IfVersion>
  <IfVersion >= 2.4>
    IncludeOptional /opt/docker/etc/httpd/vhost.common.d/*.conf
  </IfVersion>

</VirtualHost>

<VirtualHost *:443>
  ServerName docker.vm
  ServerAlias *.vm
  DocumentRoot "/var/www/html"

  UseCanonicalName Off

  <IfVersion < 2.4>
    Include /opt/docker/etc/httpd/vhost.common.d/*.conf
  </IfVersion>
  <IfVersion >= 2.4>
    IncludeOptional /opt/docker/etc/httpd/vhost.common.d/*.conf
  </IfVersion>

  Include /opt/docker/etc/httpd/vhost.ssl.conf
</VirtualHost>

I think it helps using docker exec -it bash and analyzing the container and its directories to see what is going on.

Is this answer sufficient?

htuscher commented 6 years ago

Closed due to inactivity