nginx "try_files" directive is not allowed here nginx "try_files" directive is not allowed here nginx nginx

nginx "try_files" directive is not allowed here


You could use regexps in server_name. So it's better to use two server blocks.

server {    listen 8080 default_server;    root /path/to/current/web;    location / {        try_files $uri @rewriteapp;    }     location @rewriteapp {        rewrite ^(.*)$ /site.php/$1 last;    }    ...}server {    listen 8080;    server_name ~^admin;    # or better, if they all starts with "admin." token    # server_name admin.*;    root /path/to/current/web;    location / {        try_files $uri @rewriteadmin;    }     location @rewriteadmin {        rewrite ^(.*)$ /admin.php/$1 last;    }    ...}


Quick answer: try_files needs to be inside a location.

Quick fix:

location / {    try_files $uri $uri/ /index.php?$args;}

Works for my CakePHP v 3.x