Wednesday, March 8, 2017

Multiple Laravel Projects on a single domain with NGINX

At work we have a single staging server with a staging domain, something like https://staging.example.com. We recently decided to switch from Apache to NGINX on a new server and we're having issues with our Laravel routing.

All of our laravel apps sit in sub-directories on the staging server, like so.

I've tried configuring the NGINX conf file as specified in the Laravel docs but get a 404 when accessing any 2nd level route, i.e. https://staging.example.com/app1/public/a/b

Using something like the below config, I can access all the routes in an app.

location @laravel {
        rewrite /santern/public/(.*)$ /santern/public/index.php?$1;
}

location / {
        try_files $uri $uri/ @laravel;
}

However, we have many apps hosted on this server and we don't want to have to update an NGINX conf file every time we want to add an app to the server.

Is there a way of constructing a rewrite to apply to any sub-directory and keep Laravel's routing system working?

Note: I've also tried this rewrite rewrite (.*)/(.*)$ $1/index.php?$2 and that doesn't work for 2nd level routes.



via Enijar

Advertisement