我在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/