We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Nginx with phalcon - multiple projects

I'm using PHP with Phalcon framework in my projects and this is my current structure. Note: I'm not using multi-module.

inserir a descrição da imagem aqui

My Nginx:

server {
    listen   80;

    server_name 123.123.123.123;
    root /var/www/myproject.com.br;

    location @site{
        rewrite ^/public(.+)$ /public/index.php?_url=$1 last;
    }

    location / {
        index index.php;
        if ($uri !~ ^/public) {
            rewrite ^(.*)$ /public$1;
        }
        try_files $uri $uri/ @site;

        location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
            root /var/www/myproject.com.br/public;
        }
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

}

It's working perfectly in my root phalcon project using the above nginx configuration. But now I need to make it work prioritizing subfolders instead of the root projects, for example: If myproject.com.br, then load the main project in root, it is already working with the code I posted previously. But when myproject.com.br/v2, then I need to use the phalcon project inside the /v2/ folder, and so on (to /online, /cpanel too).

I know the correct way of doing it is using phalcon multiple-module feature. But this project was created from the maintainer before me, and there are codes inside these sub-folders that includes models, libraries and many things from the main root project. I'm focusing on making these redirects work first because I'm already migrating from apache to nginx for performance issues (even it was already fast before this migration), so something is going to better, hahaha.

Sorry, my english is not good.

edited Dec '15

I don't think youll need to change the nginx config, simply change the base URI on the Url service inside the v2 folder:

https://docs.phalcon.io/en/latest/reference/url.html