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

Phalcon/Nginx help

Hi, i would enable some folders under the nginx webroot tree to using phalcon, leaving the others with the "simple"php support. For example, under "mynginxserver.intranet", I have a folders structure like this:

nginx_document_root
|
+---- normal_php_application_1
|       |
|       +---- "some files & folders"
|
+---- phalcon_enabled_application
|       |
|       +---- "phalcon folders structure"
|
+---- normal_php_application_2
        |
        +---- "some files & folders"

so, I can refer to the applications with these urls:

https://mynginxserver.intranet/normal_php_application_1
https://mynginxserver.intranet/phalcon_enabled_application
https://mynginxserver.intranet/normal_php_application_2

With apache, this is quite simple to accomplish, but with ngix I cannot figure how to make the right configuration. This is mainly due to my low nginx configuration skills... Using the examples given in the phalcon documentation, I can enable ALL folders to use phalcon, but my attemps fails in achieving a behavior like the one described above... can anyone help me with this task? Thanks.

You need to create 2 pools in php-fpm - one which will have phalcon enabled and second which will don't. Nginx is only webserver, it doesn't have anything to do with php.



1.5k

php-fpm isn't the right piece to move to solve this puzzle. The goal is to force ngix to route the requests through public/index.php only for phalcon_enabled_application and serve normal_php_application_1 and normal_php_application_2 as usual. To acheive this, nginx must be configured properly. After a number of attempts, configuring the rewrite for the phalcon_enabled_application location with this command:

rewrite ^/phalcon_enabled_application/(.*)$ /phalcon_enabled_application/public/index.php?_url=/$1;

I can obtain the desidered behavior... more or less. With this kind of rewrite, all the request (even images, css files or javascript snippets), goes through public/index.php... any suggestion for solve this?

edited May '16

Why don't you just map your 3 apps to a different nginx vhost sites? It would be much cleaner. The other way around would be to define location blocks in nginx, all three in one server config file.

location /normal_php_application_1{
root /usr/share/nginx/normal_php_application_1
#other directives...
}

location /normal_php_application_2{
root /usr/share/nginx/normal_php_application_2
#other directives...
}

location /phalcon_enabled_application{
root /usr/share/nginx/phalcon_enabled_application
#other directives...
}

And for serving static content, you need to tell nginx to handle it:

location / {
    try_files $uri $uri/ /index.php$is_args$query_string;
}
edited May '16

But there be still access to phalcon all of those locations/roots. You must use php-fpm, also create seperated instances of it(beacause as i checked there is no way to set extensions for pools).

If you want other thing - that in normal_php_application_1 and _2 you can just access any php file they just should look like above, but if you want in phalcon to use index.php as front controller for all addresses then you need to add in phalcon_enabled_application:

try_files $uri $uri/ /index.php$is_args$query_string;