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

How to configure nginx for Phalcon?

Following is my directory structure.



I am creating rest api from ng-app directory and it will pass all this url to api directory. in api directory i am using PhalconPHP.

How can can i set up nginx configure file for this

edited Aug '17

FIrst, decide your router source strategy. It can either come from a get query _url variable, or from the global $_SERVER[REQUEST_URI] variable. I usually use the second approach:

in your router service setup

$router = new Router();


server {
    listen      80;
    server_name localhost.dev;
    root        /var/www/your-project/ng-app;
    index       index.html index.htm;
    charset     utf-8;

    location / {
        try_files $uri $uri/ /index.html; # <- this will route all 404 pages to your index.html inside the ng-app folder

    location ~ \.php$ {
        root /var/www/your-project/api/public; # <- changes root dir for php files
        try_files     $uri =404;

        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 ~ /\.ht {
        deny all;