首页 > 解决方案 > 如何使用 Laravel Forge 和 AWS 在专用域上创建自定义子域?

问题描述

我无法将 Laravel 5.2 应用程序从 cPanel / phpMyAdmin 迁移到 Laravel 5.8、Forge 和 AWS。

使用旧系统,我们能够让我们的用户在他们自己的品牌域以及我们平台上的子域上创建自定义子域。

例如*.theircompany.com// 这不起作用

*.ourcompany.com// 这有效

其中 * 是在我们平台上创建的子域。

这是通过让用户创建指向我们的根域的 CNAME 记录,并通过具有 /public_html 文档根的 cpanel 将用户域停放在我们的域列表中来实现的

我们希望为我们的用户保持尽可能简单,只使用 cname,因为现有用户会被迁移打乱。

在 Laravel 5.2 中,我相信“索引”文件是 server.php,位于 public_html 中,看起来像这样

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylorotwell@gmail.com>
 */


$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

当我访问用户域上的子域时,我收到 404 nginx 错误。

404 Not Found
nginx/1.15.8

所以我猜这个错误是因为 nginx 配置,但我不知道如何调试。

但是,我可以看到请求正在登录/var/log/nginx/access.log

[17/Jul/2019:17:42:40] "GET /tesrt HTTP/1.1" 404 185 "-" "Mozilla/5.0 

如何使用 Laravel Forge 和 AWS 实现这一点?Route53 有必要吗?

标签: phplaravelamazon-web-servicesnginx

解决方案


添加第二个服务器块使用 http(非 https)端口 80 修复了此问题

server {
    listen 80;
    listen [::]:80;
    server_name ~. "";

    # ... same config without SSL
}

推荐阅读