简体   繁体   中英

NGiNX: PHP files from an other location + fallback to bootstrap index.php

I have two directories having the same structure directory A has all files, directory B only files that differ from A (ie an other logo.png). In addition I am running a ZendFramework that has a management and admin module where the bootstrap (index.php) should be triggered.

So www.my.com , www.my.com/admin/ and www.my.com/management should trigger the bootstrap file and all other locations should first been looked up in dir A and then in B and php files should be run from both folders.

I was searching and trying for hours and hours to solve this problem but I think there must be a better or easier way.

Is there?

Strange about it was that either the index.php from ZF was downloaded instead of executed or the other php files where downloaded an not executed. The trick did the part in location ~* \\.php$ .

Here we go with my config files

server {
    ...

    root /var/www/clients/B/public/;

    # ZendFramework run bootstrap index.php
    location ~ ^/(management|admin)(?:/|\z) {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~* \.php$ {
        include php.conf;
        try_files $uri $uri/ @fallbackPHP;
    }

    location / {
        try_files $uri $uri/ @fallback;
    }

    location @fallback {
        root /var/www/clients/A/public/;
    }

    location @fallbackPHP {
        root /var/www/clients/A/public/;
        include php.conf;
    }
}

and the included php.conf

try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass php5-fpm-sock-B;
include /etc/nginx/fastcgi_params;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM