Tuesday, May 6, 2014

URL Rewriting: CakePHP + Nginx + Subdirectory

I have a number of different CakePHP applications running on an Nginx server, however I'm having a lot of trouble getting php files inside my app/webroot folder to render.

My current config works with all other scenarios: general url rewriting, static asset loading,etc; here is my config:



    location /FormGenerator {
        rewrite_log on;
        error_log /var/log/nginx/notice.log notice; # just for debuggin

        if (-f $request_filename) {
            break;
        }

        if ($request_uri ~ /webroot/index.php) {
            break;
        }

        rewrite ^/FormGenerator$ /FormGenerator/ permanent;
        rewrite ^/FormGenerator/app/webroot/(.*) /FormGenerator/app/webroot/index.php?url=$1&$args last;
        rewrite ^/FormGenerator/(.*)$ /FormGenerator/app/webroot/$1 last;
    }


    location ~ \.php$ {
        try_files $uri = 404;
        fastcgi_pass   unix:/var/run/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_read_timeout 180;
        include        fastcgi_params;
    }


My skills are still elementary when it comes to configuring Nginx, so any guidance would be greatly appreciated.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: