简体   繁体   English

Docker php 与 apache 在 localhost:ERR_SSL_PROTOCOL_ERROR

[英]Docker php with apache on localhost: ERR_SSL_PROTOCOL_ERROR

I am trying to serve a hello_world.php file with apache and php in a docker container on Windows 10 with Docker Desktop. I am trying to serve a hello_world.php file with apache and php in a docker container on Windows 10 with Docker Desktop.

Here's the Dockerfile:这是 Dockerfile:

FROM php:7.3-apache
# install git and zip, both needed for composer
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y git && \
    apt-get install zip unzip
# install composer
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/bin --filename=composer && chmod +x /usr/bin/composer 

RUN a2enmod headers
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
COPY . /var/www/html
WORKDIR /var/www/html

#RUN composer install
EXPOSE 80

As you can see, some of the additional code for setting up composer etc. (so I can dockerize an existing PHP application) is even commented out but it does not work with even a basic hello world php file and no other files (no .htaccess for example).如您所见,用于设置作曲家等的一些附加代码(因此我可以对接现有的 PHP 应用程序)甚至被注释掉,但它甚至不适用于基本的 hello world php 文件且没有其他文件(无 Z80252C42AB88A8AA0例如)。

Firstly, I build the image with docker build.首先,我使用docker build. . . When I then execute docker run -it -p 8000:80 d7cd1255a20f , I get the console output然后当我执行docker run -it -p 8000:80 d7cd1255a20f时,我得到了控制台 output

[Tue Jun 02 16:01:29.592455 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.18 configured -- resuming normal operations
[Tue Jun 02 16:01:29.592531 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

Looks fine to me.在我看来很好。 I open http://localhost:8000 in my browser and get "Can't establish a secure connection. ERR_SSL_PROTOCOL_ERROR".我在浏览器中打开http://localhost:8000并得到“无法建立安全连接。ERR_SSL_PROTOCOL_ERROR”。 The server log shows (two lines each time I load the page in my browser):服务器日志显示(每次我在浏览器中加载页面时两行):

172.17.0.1 - - [02/Jun/2020:16:02:55 +0000] "\x16\x03\x01\x02" 400 0 "-" "-"
172.17.0.1 - - [02/Jun/2020:16:02:55 +0000] "\x16\x03\x01\x02" 400 0 "-" "-"

I have already researched this and it looks like it's the beginning of a TLS handshake.我已经对此进行了研究,看起来这是 TLS 握手的开始。

How can I get this to work?我怎样才能让它工作?

Do you have any .htaccess file inside /var/www/html ?您在/var/www/html中有任何 .htaccess 文件吗? It looks like Apache is performing an automated redirect to HTTPS.看起来 Apache 正在执行到 HTTPS 的自动重定向。 Building the image with an empty directory as /var/www/html and running docker run -it -p 8000:80 d7cd1255a20f correctly runs over HTTP.使用/var/www/html的空目录构建映像并运行docker run -it -p 8000:80 d7cd1255a20f正确地在 HTTP 上运行。

okay Try this好的试试这个

Follow the folder structure遵循文件夹结构

phpExample/
   php/
      index.php
   dockerfile

dockerfile dockerfile

FROM php:7.3-apache
COPY php/ /var/www/html
EXPOSE 80

index.php index.php

<?php
echo "Hello World from Docker container using PHP<br>";
echo '<img src="https://www.docker.com/sites/default/files/d8/2019-07/Moby-logo.png">';
?>

After this run following command在此之后运行以下命令

docker build -t helloWorld-php-docker .

When the build is completed.构建完成时。

docker run -p 80:80 helloWorld-php-docker

Please make sure port 80 is not in use, or what you can do change the port number请确保端口 80 未被使用,或者您可以做些什么来更改端口号

PS: directory structure is not mandatory. PS:目录结构不是强制性的。 I added just to structure the example我添加只是为了构建示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM