我一直在尝试构建一个多站点 Apache docker,但一切都是徒劳的。 这是我的 docker-compose.yml
version: '3.9'
services:
app:
container_name: Core
build:
context: ./conf/core
args:
UID: ${UID:-1000}
env_file:
- "./.env"
ports:
- "${HTTP_PORT:-80}:80"
- "${HTTPS_PORT:-443}:443"
volumes:
- ./../application:/var/www/html
- ./conf/core/php.ini:/usr/local/etc/php/conf.d/99-overrides.ini
- ./conf/core/openssl.cnf:/etc/ssl/openssl.cnf
- ./conf/ssl:/etc/apache2/ssl
- ./logs/apache:/var/log/apache2
networks:
- abmmhasan-net
networks:
abmmhasan-net:
driver: bridge
docker 文件
FROM php:8.2-apache
# Configureing Apache
ENV APACHE_RUN_USER=#$UID
ENV APACHE_RUN_GROUP=#$UID
ENV APACHE_LOG_DIR=/var/log/apache2
RUN rm -rf /etc/apache2/sites-enabled/000-default.conf /etc/apache2/sites-enabled/default-ssl.conf
RUN rm -rf /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/default-ssl.conf
ADD ./sites/*.conf /etc/apache2/sites-available
RUN echo "ServerName site1.local" >> /etc/apache2/apache2.conf
RUN echo "ServerName site2.local" >> /etc/apache2/apache2.conf
RUN a2ensite *
RUN a2enmod rewrite ssl socache_shmcb vhost_alias
# Required installations/updates
RUN apt update && apt upgrade -y
RUN apt install sudo -y && apt clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/archives/*
# Add synced system user
ARG UID
RUN useradd -G www-data,root -u $UID -d /home/devuser devuser && \
mkdir -p /home/devuser/.composer && \
chown -R devuser:devuser /home/devuser
USER devuser
WORKDIR /var/www/html
以及 ./sites/site1.local.conf (与 site2 和 site2 目录相同)文件
<VirtualHost site1.local:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/site1
DirectoryIndex index.php
ServerName site1.local
#<Directory /var/www/html/site1>
#Options Indexes FollowSymLinks
#AllowOverride All
#Require all granted
#</Directory>
ErrorLog ${APACHE_LOG_DIR}/site1-error.log
CustomLog ${APACHE_LOG_DIR}/site1-access.log common
</VirtualHost>
我还在我的主机文件中添加了以下内容
127.0.0.1 site1.local
127.0.0.1 site2.local
尝试在单个位置托管多个站点的单个 docker 容器,但不是从定义的目录加载站点,而是仅从
/var/www/html/
加载!!
在你的主机文件中它不会是
127.0.0.1 site1.local
它会是别的东西,检查你的docker容器本地IP地址,并将其放在那里docker_ip_here site1.local
使用此命令获取其 IP 地址,将
container_name_or_id
替换为您的文档名称/id
docker inspect \
-f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
如果在 Windows 上使用此命令
docker inspect \
-f "{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}" container_name_or_id