【问题标题】:How to properly setup two domains pointing in same application with Laravel 5.0如何使用 Laravel 5.0 正确设置指向同一应用程序的两个域
【发布时间】:2018-08-14 09:05:08
【问题描述】:

我有两个域。假设 reports.test.comreport.test.com 指向一个 Laravel 5.0 应用程序。有时在我的日志文件中,它显示NotFoundHttpException in RouteCollection.php line 145: 错误。 为什么我的应用程序会记录 NotFoundHttpException?

这些是我的日志文件的位置

 http://reports.test.com/storage/logs/laravel-2018-08-13.log
 http://report.test.com/storage/logs/laravel-2018-08-13.log

【问题讨论】:

  • 什么意思?当您向 report.test.com 发出 http 请求时,http 响应为 404 ?
  • 有时 report.test.com 正在工作,而此时 reports.test.com 不工作,反之亦然
  • 看,这真的是网络服务器的问题,而不是你的后端(laravel),当请求到达网络服务器时它会触发 laravel,laravel 做出响应并提供给网络服务器和网络服务器给它回客户端。所以请确保对于这两个域,请求都来自您的 laravel 应用程序。在你的 public/index.php 文件中做一个 die('executed') 并请求你的两个域并检查请求是否到达 laravel。
  • 您能否提供有关您的安装的更多详细信息?你用什么作为你的网络服务器?详细说明您的设置,以便我们更好地为您提供帮助。你能说明这个异常是在哪条路由上启动的吗?
  • 访问者访问的网址不再属于您的网站。

标签: laravel laravel-5


【解决方案1】:

正确使用它的一种方法是使用一个域作为主域,第二个域作为重定向到主域。

  • 确保您只安装了一个 Laravel 应用实例

1。选择一个子域作为 primary,另一个作为 parked (secondary) 域。假设reports 将是主要的。

2。将两条 DNS A 记录指向您的网络服务器 IP

A reports.test.com  123.123.123.123 # IP is just an example
A report.test.com   123.123.123.123 # IP is just an example

3。配置您的网络服务器以重定向到您的主域

例如,nginx serverblock 会是这样的:

server {
    listen      80;
    server_name report.test.com;
    # ...
    rewrite ^ http://reports.test.com$request_uri? permanent;
}

# ... (your main app serverblock)

使用特权用户编辑 serverblock # service nginx reload 后重新启动 nginx。

4。确保您的 .env 文件使用主域

APP_URL="http://reports.test.com"

如果您正在使用配置缓存,请使用您的部署用户更新缓存:php artisan config:cache


请注意,如果您愿意使用 HTTPS,可能需要根据需要进行编辑。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    • 2015-09-16
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多