通过 ngrok 公开 localhost Magento 时的 302 重定向响应

302 redirect response when exposing localhost Magento via ngrok

提问人:Ricky 提问时间:9/26/2023 最后编辑:Ricky 更新时间:9/26/2023 访问量:87

问:

我已经设置了一个本地Magento 2,可以按预期通过浏览器或curl命令访问:

  1. http://localhost/men/tops-men/jackets-men.html

  2. http://localhost

我有一个任务是公开本地环境,以便其他人可以测试某些服务,所以我选择了 ngrok。我使用以下命令启动了 ngrok:

  1. ngrok http --host-header=localhost 80

  2. ngrok http --host-header=重写 80

但他们都得到了相同的结果:302 无限重定向。

这是我运行 curl http://localhost/men/tops-men/jackets-men.html 时的 Apache 日志,当我卷曲相应的 ngrok url 时,日志与最后一行是“302”而不是“200”完全相同

[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] add path info postfix: /var/www/magento2/pub/men -> /var/www/magento2/pub/men/tops-men/jackets-men.html
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] strip per-dir prefix: /var/www/magento2/pub/men/tops-men/jackets-men.html -> men/tops-men/jackets-men.html
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] applying pattern '.*' to uri 'men/tops-men/jackets-men.html'
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] add path info postfix: /var/www/magento2/pub/men -> /var/www/magento2/pub/men/tops-men/jackets-men.html
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] strip per-dir prefix: /var/www/magento2/pub/men/tops-men/jackets-men.html -> men/tops-men/jackets-men.html
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] applying pattern '.*' to uri 'men/tops-men/jackets-men.html'
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] add path info postfix: /var/www/magento2/pub/men -> /var/www/magento2/pub/men/tops-men/jackets-men.html
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] strip per-dir prefix: /var/www/magento2/pub/men/tops-men/jackets-men.html -> men/tops-men/jackets-men.html
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] applying pattern '.*' to uri 'men/tops-men/jackets-men.html'
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] rewrite 'men/tops-men/jackets-men.html' -> 'index.php'
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] add per-dir prefix: index.php -> /var/www/magento2/pub/index.php
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] strip document_root prefix: /var/www/magento2/pub/index.php -> /index.php
[rid#ffffbdc980a0/initial] [perdir /var/www/magento2/pub/] internal redirect with /index.php [INTERNAL REDIRECT]
[rid#ffffbdc8d760/initial/redir#1] [perdir /var/www/magento2/pub/] strip per-dir prefix: /var/www/magento2/pub/index.php -> index.php
[rid#ffffbdc8d760/initial/redir#1] [perdir /var/www/magento2/pub/] applying pattern '.*' to uri 'index.php'
[rid#ffffbdc8d760/initial/redir#1] [perdir /var/www/magento2/pub/] strip per-dir prefix: /var/www/magento2/pub/index.php -> index.php
[rid#ffffbdc8d760/initial/redir#1] [perdir /var/www/magento2/pub/] applying pattern '.*' to uri 'index.php'
[rid#ffffbdc8d760/initial/redir#1] [perdir /var/www/magento2/pub/] strip per-dir prefix: /var/www/magento2/pub/index.php -> index.php
[rid#ffffbdc8d760/initial/redir#1] [perdir /var/www/magento2/pub/] applying pattern '.*' to uri 'index.php'
[rid#ffffbdc8d760/initial/redir#1] [perdir /var/www/magento2/pub/] pass through /var/www/magento2/pub/index.php
192.168.65.1 - - [26/Sep/2023:08:28:04 +1000] "GET /men/tops-men/jackets-men.html HTTP/1.1" 200 4407 "-" "curl/8.1.2"

这是浏览器中的结果

enter image description here

以下是 ngrok 提供的屏幕截图信息

enter image description here

感谢您提供任何可以帮助我的信息!

Apache Magento Magento2 virtualhost ngrok

评论


答:

0赞 Ricky 9/26/2023 #1

通过更新Magento中的商店配置可以找到解决方案:商店/配置/常规/Web/URL选项/自动重定向到基本URL到否为我解决了这个问题。

解决方案在这里找到:https://github.com/shkoliar/magento-ngrok/issues/3#issuecomment-652586969