1

I want to run a PhalconPHP application on a subfolder like this http://stg.example.org/simon/apps/phalconapp/

A snippet of my Nginx configuration is as below...

location ^~ /simon/apps/phalconapp {

      root /var/www/stg.example.org/simon/apps/phalconapp/public;
      index index.php index.html index.htm;
      try_files $uri $uri/ @rewrite;     

      location ~ \.php$ {

            fastcgi_pass   127.0.0.1:9000;  
            fastcgi_index  index.php;

            include fastcgi_params;

            fastcgi_split_path_info       ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

      }

  }

  location @rewrite {
     rewrite ^/(.*)$ /index.php?_url=/$1;
  }

I however, get a file not found error when trying to access the application. What could I be doing wrong?

========= updated configuration

      location ^~ /simon/apps/phalconapp {

             alias /var/www/stg.example.org/simon/apps/phalconapp/public;
             index index.php index.html index.htm;
             try_files $uri $uri/ @rewrite;

          if (!-e $request_filename) {
              rewrite ^ /simon/apps/phalconapp/public/index.php?_url=/$1 last;
          }

         location ~ \.php$ {

         if (!-f $request_filename) {
              rewrite ^ /simon/apps/phalconapp/public/index.php?_url=/$1 last;
          }

            fastcgi_pass   127.0.0.1:9000;  #set port for php-fpm to listen on
            fastcgi_index  index.php;
            try_files $uri =404;

            include fastcgi_params;
            include /etc/nginx/fastcgi_params;

            fastcgi_split_path_info       ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

      }

  }

  location @rewrite {
       rewrite ^/(.*)$ /simon/apps/phalconapp/public/index.php?_url=/$1;
  }

======= Almost working configuration 2

 location ^~ /simon/apps/phalconapp {

     alias /var/www/stg.example.org/simon/apps/phalconapp;
     index index.php index.html;
     try_files $uri $uri/ @rewrite; 

    location ~ \.php$ {

        fastcgi_pass   127.0.0.1:9000;  
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $request_filename;
        include  fastcgi_params;              
        include /etc/nginx/fastcgi_params;

     }

}

location @rewrite {
     rewrite ^/(.*)$ /simon/apps/phalconapp/public/index.php?_url=/$1;
}
  • Nginx is looking for files at /var/www/stg.example.org/simon/apps/phalconapp/public/simon/apps/phalconapp, so you need to use alias instead of root. See this answer. Your @rewrite block is also incorrect, the correct URI should be: /simon/apps/phalconapp/index.php and not /index.php. – Richard Smith Jun 10 at 7:34
  • Thanks @RichardSmith. I have updated configuration as shown above but the problem persists:- – Obirieni Simeo Jun 10 at 8:12
  • You have left the try_files statements in. You don't need try_files and the if blocks, they are both doing the same job. Use fastcgi_param SCRIPT_FILENAME $request_filename; when using alias. – Richard Smith Jun 10 at 8:36
  • I managed to get it to work using configuration 2, above. However, I am unable to get Phalcon to interpret the URI correctly. It should interpret it as stg.example.org/simon/apps/phalconapp/<module>/<controller>/<action> , but is instead interpreting simon as the module, apps as controller etc. Any clues on how to make Phalcon understand that /simon/apps/phalconapp/ is just the base uri? – Obirieni Simeo Jun 10 at 13:39
0

This configuration has worked for me. I will however appreciate if this answer can be improved by someone who is more knowledgeable with Nginx configurations.

  location ^~ /simon/apps/phalconapp {

      alias /var/www/stg.example.org/simon/apps/phalconapp;
      index index.php index.html;
      try_files $uri $uri/ @rewrite; 

      location ~ \.php$ {

          fastcgi_pass   127.0.0.1:9000; 
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME $request_filename;
          include  fastcgi_params;              
          include /etc/nginx/fastcgi_params;
     }
}

location @rewrite {
   rewrite ^/simon/apps/phalconapp(.*)$ /simon/apps/phalconapp/public/index.php?_url=$1 ;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.