Перенаправление обработки скрипта в другую папку

server {
                                listen 192.168.1.1:80;
                                server_name site.ztc ;
                                root /home/site.ztc/httpdocs/app/frontend/web;
                                index index.php;
                                access_log /home/site.ztc/logs/access.log;
                                error_log  /home/site.ztc/logs/error.log error;
                                charset utf-8;
 
                                # With PHP-FPM
                                location / {
                                                index index.php;
                                                try_files $uri $uri/ /index.php?$query_string;
                                }
 
                                # PHP fastcgi
                                location ~ \.php {
                                                include fastcgi_params;
                                                # Use your own port of fastcgi here
                                                #fastcgi_pass 127.0.0.1:9000;
                                                fastcgi_pass unix:/var/run/php-fpm-7-site.ztc.sock;
                                                fastcgi_index index.php;
                                                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                                                fastcgi_param PATH_INFO $fastcgi_path_info;
                                                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                                }
 
 
                                # rpc
                                location ^~ /rpc {
                                                alias /home/site.ztc/httpdocs/app/api/web;
                                                index index.php;
                                                try_files $uri $uri/ @rpc;
 
                                                # PHP fastcgi
                                                location ~* \.php {
                                                               include fastcgi_params;
                                                               # Use your own port of fastcgi here
                                                               #fastcgi_pass 127.0.0.1:9000;
                                                               fastcgi_pass unix:/var/run/php-fpm-7-site.ztc.sock;
                                                               fastcgi_split_path_info ^(.+\.php)(/.+)$;
                                                               fastcgi_param SCRIPT_FILENAME $request_filename;
                                                }
                                }
 
                                location @rpc {
                                    rewrite ^/rpc/(.*)$ /rpc/index.php?$1 last; # THIS IS THE IMPORTANT LINE
                                }
                                # end rpc
 
}
  • @rpc - Этот локейшен необходим для перенаправления c /rpc на /rpc/index.php. Указываем last для отключения дальнейшего реврайта
  • $request_filename - равносильно fastcgi_param SCRIPT_FILENAME /home/site.ztc/httpdocs/app/api/web/$script;