我正在尝试在容器中创建虚拟主机php5.6-apache
,但是当我尝试运行命令 a2ensite 时。
我的 host_1 文件:
<VirtualHost *:80>
ServerName local.website1.dev
DocumentRoot /var/www/html/codeigniter_first/public_html/
Options Indexes FollowSymLinks
<Directory "/var/www/html/codeigniter_first/public_html/">
AllowOverride All
<IfVersion < 2.4>
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
</VirtualHost>
我的 host_2 文件:
<VirtualHost *:80>
ServerName local.website2.dev
DocumentRoot /var/www/html/codeigniter_second/public_html/
Options Indexes FollowSymLinks
<Directory "/var/www/html/codeigniter_second/public_html/">
AllowOverride All
<IfVersion < 2.4>
Allow from all
</IfVersion>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
</Directory>
</VirtualHost>
我的Docker文件:
ARG PHP_VERSION=7.2-apache
FROM php:${PHP_VERSION}
RUN docker-php-ext-install mysqli
RUN docker-php-ext-install pdo pdo_mysql
COPY vhost.conf /etc/apache2/sites-enabled/vhost.conf
COPY php56.ini /usr/local/etc/php/php.ini
COPY sites/website1.com.conf /etc/apache2/sites-enabled/website1.com.conf
COPY sites/website2.com.conf /etc/apache2/sites-enabled/website2.com.conf
我的 Docker Composer 文件:
version: "2"
services:
########################################################
#### PHP and Apache Config
########################################################
www:
build:
context: ./docker-config/php-apache
args:
- PHP_VERSION=5.6-apache
- XDEBUG_REMOTE_HOST=192.168.1.70
container_name: rp-app-workspace
ports:
- "80:80"
volumes:
- "./workdir-apps:/var/www/html/"
- "./docker-config/php-apache/logs:/var/log/apache2"
- "./docker-config/php-apache/sites:/etc/apache2/sites-available"
links:
- db
- memcached
networks:
- default
########################################################
#### Volume Configuration
########################################################
volumes:
persistent:
当我构建我的docker容器时,虚拟主机不起作用。当我尝试添加命令a2ensite
在docker文件中运行时,它显示ERROR: Site website1.com does not exist!
构建错误
RUN a2ensite website1.com.conf
RUN a2ensite website2.com.conf
我还尝试改变在docker文件顶部复制文件和在底部运行命令的位置。
答案1
您使用了错误的目录来放置虚拟主机配置文件。它应该是/etc/apache2/sites-available
,因此您需要将 COPY 目标路径从 更改/etc/apache2/sites-enabled/*.conf
为/etc/apache2/sites-available/*.conf
当您运行a2ensite website1.com.conf
命令时,它将在/etc/apache2/sites-enabled
目录中创建配置符号链接。