actually this part was wrong; if (!-f $site_folder) { rewrite ^/[^/]+/(.*) /$1; } needs to be: if (!-d /etc/nginx/html/production/$site_folder) { rewrite ^/[^/]+/(.*) /$1; } * changed -f to -d ** had to add root path before $site_folder Posted at Nginx Forum: http://forum.nginx.org/read.php?2,251908,251939#msg-251939