在Apache Docker容器中运行虚拟主机 [英] Running virtual hosts in apache docker container

查看:155
本文介绍了在Apache Docker容器中运行虚拟主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一个apache容器中有两个php应用程序,我试图在端口上运行其中的一个,因为它需要通过根域而不是子文件夹进行访问.

I have two php applications in the same apache container and I'm trying to run one of them on a port since it needs to be accessible via a root domain and not a subfolder.

我想在端口8060上运行该应用程序,这是我尝试使用apache虚拟主机执行的操作,但它不会加载该页面( http://192.168.99.100 可以正常工作. 我的docker文件如下

I want to run the application on port 8060 which I've tried doing using apache virtual hosts but it won't load the page (http://192.168.99.100:8060/) it just says connection refused. However the normal root ip - http://192.168.99.100 works fine. My docker file is as follows

version: '3.2'
  services:
    php-apache:
      build:
        context: ./apache-php
      ports:
        - 80:80
        - 8060:8060

      expose:
        - '8060'
      volumes:
        - ./DocumentRoot:/var/www/html:z

我的Apache配置

<VirtualHost *:60>
    DocumentRoot /var/www/html/api
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

任何帮助将不胜感激.

推荐答案

感谢 @David Maze 我将监听指令添加到apache配置的顶部并更改了端口号的问题.

Thanks to @David Maze I found the problem I added the listen directives to the top of my apache configuration and changed the port numbers.

docker-compose.yml

docker-compose.yml

version: '3.2'
services:
  php-apache:
    build:
      context: ./apache-php
    ports:
      - 80:80
      - 8060:8060

    volumes:
      - ./DocumentRoot:/var/www/html:z

Apache配置

Listen 80
Listen 8060

<VirtualHost *:8060>
    DocumentRoot /var/www/html/api
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

目录结构

apache-php
   ¬ sqlite3_ext
   ¬ 000-default.conf (Apache config)
   ¬ Dockerfile
   ¬ php.ini
docker-compose.yml

Dockerfile

Dockerfile

FROM php:7.2.1-apache
RUN docker-php-ext-install pdo pdo_mysql mysqli

# Enable apache rewrite
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf

#Install spatialite and create symlink for libproj.so.0
COPY sqlite3_ext /etc/sqlite3_ext
RUN apt-get update && apt-get -y install gdal-bin
RUN ln -s /usr/lib/x86_64-linux-gnu/libproj.so.12 /usr/lib/x86_64-linux-gnu/libproj.so.0

#Install gd library for images
RUN apt-get install libpng-dev libfreetype6-dev libjpeg62-turbo-dev -qy \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install gd

#Copy php ini
COPY php.ini /usr/local/etc/php/php.ini
RUN a2enmod rewrite

这篇关于在Apache Docker容器中运行虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆