Next Chapter: CakePHP 4: Adding User Data

Configuring Nginx for CakePHP 4 with Subfolders

2019-04-27 09:03:03+00

You find the standard setup for Nginx with CakePHP 4 in

In our case we will use subfolder in order to develop our solution in parallel to production environment.

The Application will run in whereas /k/ is the subfolder. With the subfolder concept there are multiple versions of CakePHP possible.

server {
   listen 80;
   rewrite ^/(.*)$1 permanent; # to prevent duplicate content

server {
    listen 443 ssl http2;
    access_log /var/log/nginx-access-lf.log;
    error_log /var/log/nginx-error-lf.log;
    root /usr/local/www/lf/webroot/; # point to cakephp webroot,refer chapter setup CakePHP
    index index.php;
    server_tokens off;

    # serve static files
    location / {
      try_files $uri $uri/ /index.php?$args;

   location ^~ /k/  {    # prefix match not regular expressions
     alias /usr/local/www/lf/.../webroot/;
     try_files $uri  @kfallback;
   location @kfallback {
     set $path $request_uri;
     if ($path  ~ ^/k/(.*)$ ) {
         set $path /$1;
         rewrite ^ $path break;
     include /usr/local/etc/nginx/fastcgi_params;
     fastcgi_index index.php;
     fastcgi_intercept_errors on;
     fastcgi_param REQUEST_URI $path;
     fastcgi_param QUERY_STRING   $uri&$args;
     fastcgi_param SCRIPT_FILENAME /usr/local/www/lf/webroot/index.php;

Tag: cakephp4

Previous Chapter: CakePHP 4 Alpha Installation

Next Chapter: CakePHP 4: Adding User Data