dongling5411 2019-05-01 15:58
浏览 82
已采纳

在apache docker容器中运行虚拟主机

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.

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

My apache configuration

<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>

Any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dtzjvj3915 2019-05-02 08:15
    关注

    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

    version: '3.2'
    services:
      php-apache:
        build:
          context: ./apache-php
        ports:
          - 80:80
          - 8060:8060
    
        volumes:
          - ./DocumentRoot:/var/www/html:z
    

    Apache config

    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>
    

    Directory structure

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

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?