To run different copies of Laravel with Kubernetes and each of these serve as a service for different purpose.
The routing of different services can be achieved by using path-based routing using Ingress.
When using same domain with path-based routing, all Laravel will treat domain root (e.g. example.com) as application base url.
But, We want each Laravel treat their respective path, (e.g. example.com/service1
and example.com/service2
) as their base url.
We can use Alias
in Apache server configurations:
Alias /service1 /var/www/html/public
Add this in .htaccess
:
RewriteBase /service1/
OR
In Nginx:
# sub directory
location /sub_dir {
alias /usr/share/nginx/html/sub_dir/public;
try_files $uri $uri/ @sub_dir;
location ~ \.(php|phar)(/.*)?$ {
fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass php-fpm;
}
}
location @sub_dir {
rewrite /sub_dir/(.*)$ /sub_dir/index.php?/$1 last;
}
# end sub directory
Content in
location
block containing the PHP directives subject to change based on your overall nginx configuration