3

我使用此命令为 laravel 站点启动 ngrok,即 testsite.local:

ngrok http -host-header=rewrite testsite.local:80

我已经testsite.local定义/etc/hosts映射到127.0.0.1

这行得通,Ngrok 启动得很好,现在在某个随机的 *.ngrok.io 地址上为本地站点提供服务,我可以访问该地址。但是 laravel 应用程序中的所有 URL(例如内部链接,或用于加载 css 或 js 文件的 URL)都是我本地定义的域的绝对 URL,例如http://testsite.local/newshttp://testsite.local /css/styles.css。换句话说,我可以很好地加载网站,但其他人只会看到一堆没有样式的 html 并获得一个无法正常工作的网站。

对于使用 ngrok 并在其项目中具有绝对 URL 的任何人来说,这必须是一个普遍问题,但谷歌并没有产生任何有用的东西。

我想到了两种可能的方法:

  1. 将应用程序中的所有链接重写为相对的而不是绝对的(哦,上帝,请不要)
  2. 任何想要通过 *.ngrok.io url 访问我的站点的客户端都必须将他们自己的 /etc/hosts 文件中的“testsite.local”域映射到 ngrok.io url。

这些方法可能会奏效,但这似乎太过分了……难道没有其他人可以做的吗?

解决方案

https://stackoverflow.com/a/54488972/718980

4

3 回答 3

1

您需要使用 Apache 模块 mod_substitute。首先,启用模块:

a2enmod substitute
service apache2 restart

然后,将以下内容添加到 .htaccess 文件中:

AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|<your-local-link>|<your-ngrok-link>|in"

更多信息:https ://httpd.apache.org/docs/2.4/mod/mod_substitute.html

于 2018-06-12T17:46:02.993 回答
-1

在 xammp/apache/conf/httd.conf

DocumentRoot "C:/xampp/htdocs/{your-project-path}"

目录“C:/xampp/htdocs/{your-project-path}”

于 2017-05-29T11:51:19.867 回答
-1

在 httpd.conf 中,将 DocumentRoot 和 Directory 设置为项目的路径。

DocumentRoot "C:/xampp/htdocs/projectName" <Directory "C:/xampp/htdocs/projectName">

于 2017-05-29T11:51:59.377 回答