Php 如何为dev环境配置vhosts/apache子域?

Php 如何为dev环境配置vhosts/apache子域?,php,apache,docker,dockerfile,vhosts,Php,Apache,Docker,Dockerfile,Vhosts,我很难为PHP项目配置对子域的访问。仅适用于本地主机。 vhost(localhost.conf、backoffice.website.conf等)从Docker compose行:/dev/conf/default/sites/:/etc/apache2/from host复制到Docker计算机,并附加到Dockerfile中的apache2.conf。怎么了 子域: localhost => public_html/www/index.php (this works) backoff

我很难为PHP项目配置对子域的访问。仅适用于本地主机。 vhost(localhost.conf、backoffice.website.conf等)从Docker compose行:
/dev/conf/default/sites/:/etc/apache2/from host
复制到Docker计算机,并附加到Dockerfile中的apache2.conf。怎么了

子域:

localhost => public_html/www/index.php (this works)
backoffice.website => public_html/backoffice/index.php
api.website => public_html/api/index.php
health.website => public_html/health/index.php
正在工作的localhost.conf:

<VirtualHost *:80>
        ServerAdmin admin@website.ee
        DocumentRoot /var/www/dev/public_html/www
        ServerName localhost
        ServerAlias localhost

        <Directory /var/www/dev/public_html/www>
                        Options FollowSymLinks MultiViews
                        AllowOverride All
                        Order allow,deny
                        allow from all
        </Directory>
        ErrorLog /var/log/apache2/website.error.log
        LogLevel warn
        CustomLog /var/log/apache2/website.access.log combined

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} !^.*\.(jpg|css|js|gif|png|svg|map)$ [NC]
        RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
</VirtualHost>
<VirtualHost backoffice.website:80>
        ServerAdmin admin@website.ee
        DocumentRoot /var/www/dev/public_html/backoffice
        ServerName backoffice.website


        <Directory /var/www/dev/public_html/backoffice>
                        Options FollowSymLinks MultiViews
                        AllowOverride All
                        Order allow,deny
                        allow from all
        </Directory>

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
</VirtualHost>
FROM php:7.2-apache

RUN pecl install redis-5.1.1 \
    && pecl install xdebug-2.9.0 \
    && docker-php-ext-enable redis xdebug \
    && rm -rf /tmp/* \
    && mkdir /var/www/dev \
    && chmod -R 755 /var/www

RUN mkdir -p  /etc/apache2/from-host

RUN echo "" >> /etc/apache2/apache2.conf \
    && echo "# Include the configurations from the host machine" >> /etc/apache2/apache2.conf \
    && echo "IncludeOptional from-host/*.conf" >> /etc/apache2/apache2.conf

RUN a2enmod rewrite \
    && service apache2 restart

WORKDIR /var/www/dev
version: '3.1'

services:
  web:
    build: .
    depends_on:
      - db
    restart: always
    volumes:
      - ./dev:/var/www/dev/
      - ./dev/conf/default/sites/:/etc/apache2/from-host
    environment:
      XDEBUG_CONFIG: remote_host=10.10.10.219
    ports:
      - 8080:80
docker compose.yml

<VirtualHost *:80>
        ServerAdmin admin@website.ee
        DocumentRoot /var/www/dev/public_html/www
        ServerName localhost
        ServerAlias localhost

        <Directory /var/www/dev/public_html/www>
                        Options FollowSymLinks MultiViews
                        AllowOverride All
                        Order allow,deny
                        allow from all
        </Directory>
        ErrorLog /var/log/apache2/website.error.log
        LogLevel warn
        CustomLog /var/log/apache2/website.access.log combined

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} !^.*\.(jpg|css|js|gif|png|svg|map)$ [NC]
        RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
</VirtualHost>
<VirtualHost backoffice.website:80>
        ServerAdmin admin@website.ee
        DocumentRoot /var/www/dev/public_html/backoffice
        ServerName backoffice.website


        <Directory /var/www/dev/public_html/backoffice>
                        Options FollowSymLinks MultiViews
                        AllowOverride All
                        Order allow,deny
                        allow from all
        </Directory>

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
</VirtualHost>
FROM php:7.2-apache

RUN pecl install redis-5.1.1 \
    && pecl install xdebug-2.9.0 \
    && docker-php-ext-enable redis xdebug \
    && rm -rf /tmp/* \
    && mkdir /var/www/dev \
    && chmod -R 755 /var/www

RUN mkdir -p  /etc/apache2/from-host

RUN echo "" >> /etc/apache2/apache2.conf \
    && echo "# Include the configurations from the host machine" >> /etc/apache2/apache2.conf \
    && echo "IncludeOptional from-host/*.conf" >> /etc/apache2/apache2.conf

RUN a2enmod rewrite \
    && service apache2 restart

WORKDIR /var/www/dev
version: '3.1'

services:
  web:
    build: .
    depends_on:
      - db
    restart: always
    volumes:
      - ./dev:/var/www/dev/
      - ./dev/conf/default/sites/:/etc/apache2/from-host
    environment:
      XDEBUG_CONFIG: remote_host=10.10.10.219
    ports:
      - 8080:80

您应该在VirtualHost指令中使用
*:80
,只需更改ServerName和serveralias以匹配请求中的备用主机名


有关调试,请参见
apachectl-S

无法通过自定义域(“网站”)从主机访问,甚至无法访问主vhost。将0.0.0.0网站添加到主机上的/etc/hosts。仍然只能通过localhost:8080访问