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

Configure Nginx to work with Phalcon in a subfolder

I have the following snippet of nginx configuration:

location ^~ /simon/pms/phalcon {

 root /var/www/stg.server.org;
 index index.php index.html;
 try_files $uri $uri/ @rewrite; 

     location ~ \.php$ {

    #try_files $uri =404;
    fastcgi_pass;  #set port for php-fpm to listen on
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    #fastcgi_param  SCRIPT_FILENAME $request_filename;
    include  fastcgi_params;              
    include /etc/nginx/fastcgi_params;



location @rewrite {
   rewrite ^/(.*)$ /simon/pms/phalcon/public/index.php?_url=$uri&$args; #/$1;

I wish to access the above application through the url https://stg.server.org/simon/pms/phalcon/<Module>/<Controller>/<Action>. It has been working fine in Apache but in Nginx, I get the error Exception: Module simon is not registered in the application container.

My base url is set up as:

              $di->set('url', function() use ($config) {
                  $url = new \Phalcon\Mvc\Url();
                   return $url;

What I'm I doing wrong?

I have Phalcon running out of a subfolder inside a subfolder with the most basic NGINX config. Here's my config, it may help you find out what's going on in yours:

server {
    listen 80 default;

    client_max_body_size 18M;

    access_log /var/log/nginx/application.access.log;

    root /folder1/folder2/public;
    index index.php;

    if (!-e $request_filename) {
        rewrite ^.*$ /index.php last;

    location ~ \.php$ {
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        include fastcgi_params;


That should allow you to load at website.com and load the public folder from /folder1/folder2/public