Nginx, prioritize folders instead of "location /"

2

I use PHP with the Phalcon framework in my projects and this is the framework.

Mynginxlookslikethis:

server{listen80;server_name123.123.123.123;root/var/www/meusite.com.br;location@site{rewrite^/public(.+)$/public/index.php?_url=$1last;}location/{indexindex.php;if($uri!~^/public){rewrite^(.*)$/public$1;}try_files$uri$uri/@site;location~*^/(css|img|js|flv|swf|download)/(.+)${root/var/www/meusite.com.br/public;}}location~\.php${try_files$uri=404;fastcgi_split_path_info^(.+\.php)(/.+)$;fastcgi_passunix:/var/run/php5-fpm.sock;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}location~/\.ht{denyall;}}

It'sworkingfine,butnowwhenaninternalfolderisrequested,Ineednginxtoignorethewhole"location /" and run the same "location /" commands inside the requested folder. For example / v2 / .

How do I do this? I've tried it in many ways. I already searched Google. Anyway, my biggest problem is because Phalcon uses a different folder structure than the common one.

    
asked by anonymous 06.12.2015 / 15:37

1 answer

0

The nginx works setup order from top to bottom, ie summarizing you have to put the location of the folder you want to access above the location / or you inserted a rewrite inside the location ordme from top to bottom. >

Example:

server {
listen   80;

server_name 123.123.123.123;
root /var/www/meusite.com.br;

location @site{
    rewrite ^/public(.+)$ /public/index.php?_url=$1 last;
}
location /pastaserchecadaprimeiro {
  root /var/www/html/pastaserchecadaprimeiro;
}
location / {
    index index.php;
    if ($uri !~ ^/public) {
        rewrite ^(.*)$ /public$1;
    }
    try_files $uri $uri/ @site;

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root /var/www/meusite.com.br/public;
    }
}

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include fastcgi_params;
}

location ~ /\.ht {
    deny all;
}

}

    
12.02.2016 / 20:39