Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MAQE's avatar
Level 8

Configuring Nginx(or Forge) to handle multiple domains on one root but not wildcard

Hi again,

Is there anyway setting up multiple domains pointing to one single Laravel app.

For example, I would like one.example.com and two.example.com pointing to one app, and maybe I want the main domain pointing to another app on the same server. I do know there is the "wildcard" option available, but I think that is not I want as all sub-domains will be routed into only one app.

Or, is there a way to setting root domain with two domains separated by the comma? For instance, Root domain: one.example.com, two.example.com, four.example.com

Please suggest what I could do with this case. Thank you.

0 likes
11 replies
KbirMhrjn's avatar

Yes, there is a easy way to do it, you could do something like,


Route::group(array('domain' => 'example1.myapp.com'), function() { //normal route like you'd do Route::get('user/{id}', function($account, $id) { // }); }); Route::group(array('domain' => 'example2.myapp.com'), function() { //normal route like you'd do Route::get('user/{id}', function($account, $id) { // }); });

source http://laravel.com/docs/4.2/routing#sub-domain-routing

2 likes
kylestev's avatar

It can be accomplished via Route groups. Docs for Laravel 5 -- Docs for Laravel 4.2


Route::group(array('domain' => 'one.example.com'), function() { // routes for two.example.com go here }); Route::group(array('domain' => 'two.example.com'), function() { // routes for two.example.com go here });
1 like
MAQE's avatar
Level 8

Thanks you guys for the responses.

However, my point being is how to configure the Forge and server.

My scenario is like I would like to setup

  • api.example.com and app.example.com to share the same code and repo
  • and maybe, I want the main domain, example.com, to use another repo

That brings me to my question how could I configure Nginx(or Forge) listening for two specific domains, but using the same root folder.

I'm not sure this question should be specific to Nginx or Forge.

Is it more understandable, sorry for my bad English.

Thank you!

bashy's avatar
bashy
Best Answer
Level 65

To use multiple domains on one vhost, yes you can add them in the nginx config

server_name api.example.com app.example.com;

Then add another vhost for another site and enter that new site name in.

7 likes
bashy's avatar

No problem. Use nginx quite a bit so if you get any problems, post again!

edgeMD's avatar

@bashy, I know this is a bit old, but can you explain what you mean by "Then add another vhost for another site and enter that new site name in." a bit more?

bashy's avatar

@retrograde That's for adding in additional sites (from what I remember from a year ago :P).

1 like
edgeMD's avatar

@bashy, I am trying to add in another site similar to the OP example. In other words, I would like NewName.com to be a identical to OldName.com (OldName.com needs to still exist).

Here is what I have done.

  • created a new site on forge and changed the server name as you suggested above:

    server_name oldName.com newName.com;

  • I have set up a new domain in digital ocean with an cname of newName.com

With this setup, the newName.com is redirecting to my default digital ocean site unrelatedSite.com

There must be something I am missing in the process, which is how I came across your answer from a year ago.

ashitvora's avatar

If I were to do this using Forge API, should I add multiple aliases to the same site? And then create SSL cert for the newly added domain?

Please or to participate in this conversation.