Laravel

Separation of Admin Section on a different port in Laravel 5.x

Published on

Separation of Admin Section on a different port in Laravel 5.x
Separation of Admin Section on a different port in Laravel 5.x | Laravel Routes and Nginx https://blog.petehouston.com/2017/11/10/config-laravel-on-nginx-server/
 

I was working on a project where client wanted to have admin area on a separate port for privacy reasons.

I consulted old friend Google and searched for the any existing implementations. To my dismay, none of the solutions worked for me.

I then thought about the problem and opened RuoteServiceProvider in app\Providers directory in my project.

After a detailed inspection of the file, it hit me.

There is a map() method in this class (RouteServiceProvider) with the following code:

It means you can add your custom routes to it based on condition, so I quickly changed the implementation to the following:

Notice I’m scanning port number now for every request, that will have it’s own implications and a small over-head, also, I was unable to add an SSL certificate to this port as HTTPS uses port 443.

Please do comment if you know any technique to add SSL certificate to custom port or if I’m doing something wrong where

Now I added the following method maprAdminWebRoutes to RouteServiceProvider class:

Then I added admin-web.php file to the routes directory and added my routes to the file.


We’re not done yet!

In order for this to work, we also need to add port number to our nginx sites-enabled/YOUR-DOMAIN-CONF-FILE.conf file:

And that’s pretty much it.

Now you can access your custom routes on your custom port(s).

I hope you enjoyed this as much as I did when I implemented this.

Thanks for reading!