0

I am trying do Fastcgi server based on location.

all request /api/v1/ -> server v1:9000 and /api/v2/ -> server v2:9000 my nginx config is

server {
listen 80;
index index.php index.html;
root /var/www/public;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass v1:9000;
        if ( $uri ~ "^/api/v1/") {
            fastcgi_pass v1:9000;
        }
        if ( $uri ~ "^/api/v2/") {
                fastcgi_pass v2:9000;
        }
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
                 try_files $uri /index.php?$args;
             }
}

1 Answers1

-1

You need to use location directives for your different versions. For example:

location ^~ ^/api/v1/.+\.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass v1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
}

location ~ ^/api/v2/.+\.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass v2:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
}
Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • above configuration does not work for url /api/v1/search. rewrite or internal redirection cycle while internally redirecting to "/index.php" – Ravinder Rathi Sep 18 '17 at 10:04
  • Sorry, there was an issue with the regular expression, I've updated my answer. Anyway, these location blocks won't match the URL you gave, since it doesn't end with `.php`. – Tero Kilkanen Sep 18 '17 at 10:25