如何使用Laravel 5.0正确设置指向同一应用程序的两个域

时间:2018-08-13 18:02:49

标签: laravel laravel-5

我有两个域。假设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

1 个答案:

答案 0 :(得分:0)

正确解决该问题的一种方法是将一个域用作主域,将第二个域重定向至主域。

  • 确保仅安装了Laravel应用的一个实例

1。选择一个子域为 primary ,另一个选择为 parked secondary )域。可以说reports是主要的。

2。将两个DNS A记录都指向您的Web服务器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服务器块将如下所示:

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

# ... (your main app serverblock)

使用特权用户编辑服务器块# service nginx reload后,重新启动nginx。

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

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

如果您使用配置缓存,请与部署用户一起更新缓存:php artisan config:cache


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