无法通过docker

时间:2019-05-16 18:10:08

标签: apache docker ssl alpine

我有一个在Hyper-v上运行的虚拟机(Ubuntu 18.04)。该虚拟机是docker计算机。因此,我在单独的docker服务中构建了Lamp堆栈。我在apache服务中使用专有证书公开了端口80和443。毕竟,当我尝试在浏览器https://localhost上进行测试时,连接被拒绝。

使用telnet进行测试:

telnet localhost 443

但我收到了此消息

  

外部主机关闭了连接

使用curl测试:

curl -vk https://localhost

但我收到了此消息

  

卷曲:(35)OpenSSL SSL_connect:SSL_ERROR_SYSCALL连接到   本地主机:443

当我通过80端口进行测试时,一切都很好。

Apache Dockerfile

ARG APACHE_VERSION="2.4.32"
FROM httpd:${APACHE_VERSION:+${APACHE_VERSION}-}alpine

RUN apk update; \
    apk upgrade \
    apk add apache2-ssl \
    apk add --update openssl \
    apk add curl

RUN apk add ca-certificates && rm -rf /var/cache/apk/*

COPY my-certificate.crt /usr/local/share/ca-certificates/
COPY my-certificate.key /usr/local/share/ca-certificates/
COPY my-certificate.crt /usr/share/ca-certificates/

RUN update-ca-certificates --fresh

# Copy apache vhost file to proxy php requests to php-fpm container
COPY portal.apache.conf /usr/local/apache2/conf/portal.apache.conf

RUN echo "Include /usr/local/apache2/conf/portal.apache.conf" \
    >> /usr/local/apache2/conf/httpd.conf

RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf

EXPOSE 80 443

APACHE DOCKER-COMPOSER

apache:
    build:
      context: './apache/'
      args:
       APACHE_VERSION: ${APACHE_VERSION}
    restart: always
    depends_on:
      - php72
      - mysql8
    networks:
      - frontend
      - backend
    environment:
      ENV: "${ENV}"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ${PROJECT_ROOT}/:/var/www/html/
      - /etc/ssl:/etc/ssl
    container_name: apache

APACHE.CONF

ServerName localhost

LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so
LoadModule ssl_module /usr/local/apache2/modules/mod_ssl.so

<VirtualHost *:80>
    # Proxy .php requests to port 9000 of the php-fpm container
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php72:9000/var/www/html/$1
    DocumentRoot /var/www/html/

    <Directory /var/www/html/>
        DirectoryIndex index.php index.html
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    # Send apache logs to stdout and stderr
    CustomLog /proc/self/fd/1 common
    ErrorLog /proc/self/fd/2
</VirtualHost>

<VirtualHost *:443>

    ServerName localhost:443
    SSLEngine On 
    SSLCertificateFile /usr/local/share/ca-certificates/my-certificate.crt
    SSLCertificateKeyFile /usr/local/share/ca-certificates/my-certificate.key

</VirtualHost>

我希望在运行https://localhost时收到index.html内容,但会收到ERR_CONNECTION_CLOSED

0 个答案:

没有答案