Dazzle
Dazzle

Reputation: 3083

How to create custom subdomains on dedicated domains with Laravel Forge & AWS?

I am stuck migrating a Laravel 5.2 app from cPanel / phpMyAdmin to Laravel 5.8, Forge and AWS.

With the old system, we were able to give our users the ability to create custom subdomains on their own branded domains, as well as subdomains on our platform.

eg *.theircompany.com // this is not working

or *.ourcompany.com // this works

where * is a subdomain created on our platform.

This was achieved by getting the user to create a CNAME record pointing to our root domain, and parking the users domain in our list of domains via cpanel which has a document root of /public_html

We would like to keep this as simple as possible for our users, only using cname as existing users would otherwise be disrupted by the migration.

In Laravel 5.2, I believe the "index" file was server.php, located in public_html which looks like this

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <[email protected]>
 */


$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';

I am getting a 404 nginx error when I visit the subdomain on the users domain.

404 Not Found
nginx/1.15.8

So I guess the error is because of nginx config but I am not sure how to debug.

However, I can see the request is being logged in /var/log/nginx/access.log:

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

How can this be achieved with Laravel Forge & AWS? Is Route53 necessary?

Upvotes: 1

Views: 606

Answers (1)

Dazzle
Dazzle

Reputation: 3083

Adding a second server block fixed this using port 80 for http (non-https)

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

    # ... same config without SSL
}

Upvotes: 0

Related Questions