php - Ngrok到dockerized symfony 5的隧道在502错误网关中结束

标签 php docker symfony ngrok

我在Docker容器中有一个全新的symfony 5应用程序,需要在其中接收一些Webhook,从而使用ngrok进行隧道传输。事实是,ngrok继续向我发送502错误,而localhost访问正常。
我有点想法不对了。
使用本地主机 curl :

$ curl -v http://localhost:4080/default
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 4080 (#0)
> GET /default HTTP/1.1
> Host: localhost:4080
> User-Agent: curl/7.52.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Cache-Control: no-cache, private
< Content-Type: application/json
< Date: Thu, 23 Jul 2020 09:10:43 GMT
< PHP message: [info] Matched route "default".
< X-Powered-By: PHP/7.4.3
< X-Robots-Tag: noindex
< Content-Length: 93
< 
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact
{"message":"Welcome to your new controller!","path":"src\/Controller\/DefaultController.php"}
Docker使用本地主机时的日志:
payment_1                 | [Web Server/PHP ] Jul 23 09:10:43 |INFO | PHP    PHP message: Matched route "default". path="/usr/local/sbin/php-fpm" php="7.4.3"
payment_1                 | [Web Server/PHP ] Jul 23 09:10:43 |DEBUG| PHP     
payment_1                 | [Web Server/PHP ] Jul 23 09:10:43 |INFO | SERVER GET  (200) ]8;;https://127.0.0.1:8004/default\/default]8;;\ ip="172.20.0.1"
Ngrok开始于:
$ ngrok http 4080
ngrok by @inconshreveable                                                                                                                                                                          (Ctrl+C to quit)
                                                                                                                                                                                                                   
Session Status                online                                                                                                                                                                               
Account                       lulhum (Plan: Free)                                                                                                                                                                  
Version                       2.3.35                                                                                                                                                                               
Region                        United States (us)                                                                                                                                                                   
Web Interface                 http://127.0.0.1:4040                                                                                                                                                                
Forwarding                    http://8c882c861512.ngrok.io -> http://localhost:4080                                                                                                                                
Forwarding                    https://8c882c861512.ngrok.io -> http://localhost:4080                                                                                                                               
                                                                                                                                                                                                                   
Connections                   ttl     opn     rt1     rt5     p50     p90                                                                                                                                          
                              0       0       0.00    0.00    0.00    0.00
通过ngrok进行 curl :
$ curl -v http://8c882c861512.ngrok.io/default
*   Trying 3.137.63.131...
* TCP_NODELAY set
* Connected to 8c882c861512.ngrok.io (3.137.63.131) port 80 (#0)
> GET /default HTTP/1.1
> Host: 8c882c861512.ngrok.io
> User-Agent: curl/7.52.1
> Accept: */*
> 
< HTTP/1.1 502 Bad Gateway
< Content-length: 107
< Cache-Control: no-cache
< Connection: close
< Content-Type: text/html
< 
<html><body><h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body></html>
* Curl_http_done: called premature == 0
* Closing connection 0
Docker通过ngrok登录(与以前相同):
payment_1                 | [Web Server/PHP ] Jul 23 09:17:07 |INFO | PHP    PHP message: Matched route "default". path="/usr/local/sbin/php-fpm" php="7.4.3"
payment_1                 | [Web Server/PHP ] Jul 23 09:17:07 |DEBUG| PHP     
payment_1                 | [Web Server/PHP ] Jul 23 09:17:07 |INFO | SERVER GET  (200) ]8;;https://127.0.0.1:8004/default\/default]8;;\ ip="172.20.0.1"
Ngrok控制台(似乎可以):
HTTP Requests                                                                                                                                                                                                      
-------------                                                                                                                                                                                                      
                                                                                                                                                                                                                   
GET /default                   200 OK 
通过symfony开发服务器通过docker compose(docker-compose.yml提取)启动docker容器:
version: '3'
services:

  payment:
    build: ./payment
    command: sh -c "symfony server:stop && symfony server:start --port=4080"
    environment:
      APP_DEBUG: 1
      VAR_DUMPER_SERVER: payment_dump:8000
    volumes:
      - "./payment:/app"
      - "payment_composer:/root/composer"
    expose:
      - 4080
    ports:
      - "4080:4080"
这是Dockerfile:
FROM php:7.4-fpm-alpine

RUN apk add --no-cache \
  git \
  curl \
  openssl \
  ssmtp \
  libzip-dev \
  bash

RUN docker-php-ext-install -j$(nproc) \
  pcntl \
  zip

RUN apk add --no-cache icu-dev
RUN docker-php-ext-install intl

RUN wget https://get.symfony.com/cli/installer -O - | bash \
    && mv /root/.symfony/bin/symfony /usr/local/bin/symfony

RUN curl https://raw.githubusercontent.com/composer/getcomposer.org/d3e09029468023aa4e9dcd165e9b6f43df0a9999/web/installer | php -- --quiet \
    && mv composer.phar /usr/local/bin/composer

WORKDIR /app

ENV TZ="Europe/Paris"
ENV IS_DOCKER=1
我真的不明白怎么了。我还有其他具有类似配置的容器,看来工作正常。
我尝试使用*:4080或http://127.0.0.1:4080或某些-host-header选项重建容器以及各种ngrok命令。还尝试了不同的端口,但没有结果。
结果在浏览器中当然是相同的。

最佳答案

我已经解决了这个问题。问题出在symfony服务器内部,添加了奇怪的PHP message: [info] Matched route "default". header 。
此消息由记录器发出,应该发送到stderr。不知道它是怎么到达那里的。
由于它不遵循传统的 header 语法,因此我认为ngrok无法读取 header 并回退到502。
我提出了issue to symfony,同时使用基本的php服务器。

关于php - Ngrok到dockerized symfony 5的隧道在502错误网关中结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63051130/

相关文章:

PHP计数替换

macos - 为什么我在 MacOS 中收到 Screen is terminating 错误

php - Symfony 中的自定义配置

docker - 如何使用 Docker 公开 1 个以上的端口?

php - Elasticsearch 中可选的自父关系

php - Doctrine2 oneToOne 复合主键不可为空

php - 模板和我的文件差异

php - header 中的 AuthKey

php - Roundcube 自定义 SMTP_USER 变量

r - 如何修复在 ShinyProxy 中获取 CSS 和 Javascript 文件时出现的 '404 (Not Found)' 错误