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 with nginx redirects to a specific folder

It is a working example on Apache AddDefaultCharset UTF-8

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L] </IfModule>

My configuration file server { listen 80 default_server; charset utf-8; root /usr/share/nginx/html; index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
location ~ .php$ { try_files $uri =404; fastcgi_split_path_info ^(.+.php)(/.+)$;

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

location /resource{
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;     
    if (!-e $request_filename){
    rewrite ^(.*)$ /resource/index.php?_url=/$1 last;
    break;
    }
}

location ~ /\.ht {
    deny all;
}

}

Code $app->get('/', function () { echo 'test'; });

GET www.site.com/resource/ answer Access denied

GET www.site.com/resource//index.php answer test

Link https://ru.stackoverflow.com/questions/442737/%D0%9A%D0%B0%D0%BA-%D0%B2-nginx-%D0%BD%D0%B0%D1%81%D1%82%D1%80%D0%BE%D0%B8%D1%82%D1%8C-%D1%80%D0%B5%D0%B4%D0%B8%D1%80%D0%B5%D0%BA%D1%82%D1%8B-%D0%B2-%D0%BE%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D0%B5%D0%BD%D0%BD%D0%BE%D0%B9-%D0%BF%D0%B0%D0%BF%D0%BA%D0%B5?noredirect=1#comment465979_442737

I don't quite understand your problem, but here is a working example that I'm using on a production server, hope it helps:

server {
    listen          80;
    listen          443 ssl;
    server_name     my.site.org;
    set             $root_path '/var/www/site.org/my/public';
    root            $root_path;

    index index.php index.html index.htm;

    ssl_certificate         /etc/ssl/site.org/my.bundle.crt;
    ssl_certificate_key     /etc/ssl/private/site.org.key;

    if ($ssl_protocol = "") {
        rewrite ^/(.*) https://$server_name/$1 permanent;
    }

    try_files $uri $uri/ @rewrite;

    location ~* ^/(less|css|img|js|flv|swf|download|files)/(.+)$ {
        root $root_path;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|flv|swf)$ {
        root $root_path;
    }

    location ~ /\.ht {
        deny all;
    }

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

    location ~ \.php {
        fastcgi_index  /index.php;
        fastcgi_pass unix:/var/run/php5-fpm.sock;

        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;
    }

}
edited Aug '15

Oh wait, you want a subdirectory... with Phalcon, you usually set it up with the url component:

// services.php
$di->set('url', function () {
    $url = new Url();
    $url->setBaseUri('/resource/');
    return $url;
});


76

I had to deal with something similiar today, it worked for me, can you please try:

server {
    listen 80;
    server_name localhost;

    default_server;
    charset utf-8;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

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

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_index /index.php;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
        fastcgisplitpath_info ^(.+.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $root_path$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $root_path$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }
}