2

I'm having a problem getting nginx configuration to work. Seems like everything works fine but my php script does not receive GET parameters. The most relevant link I get on my issue is this one nginx + php-fpm - where are my $_GET params? But my config is slightly different and simply adding $query_string to the last try_files directive just doesn't work.

Here's my config:

server {
    server_name  api.example.com;
    root   /home/example/api/web;

    location /v2 {
        alias /home/example/api/v2/web;
        try_files $uri /v2/index.php;
        location ~* \.(js|css|less|png|jpg|jpeg|gif|ico|woff|ttf|svg|tpl)$ {
            expires 24h;
            access_log off;
        }
        location /v2/index.php {
            fastcgi_index  index.php;
            fastcgi_pass php56;
            fastcgi_split_path_info       ^/v2/(.+\.php)(.*)$;
            fastcgi_param SCRIPT_FILENAME  /home/example/api/v2/web/$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_NAME /v2/index.php;
        }
    }

}

Then using this config, /v2 URL does not see GET, while /v2/index.php does. If I change try_files line to try_files $uri /v2/index.php$query_string;, /v2 URL just gives me 404.

Andrey
  • 201
  • 1
  • 2
  • 5
  • Did you modify `/etc/nginx/fastcgi_params`? This file _should never be edited_. Get an [original copy of it](https://raw.githubusercontent.com/nginx/nginx/master/conf/fastcgi_params) and restore it. Place your own customizations elsewhere. – Michael Hampton Jun 30 '15 at 13:26
  • No, unfortunately it's unchanged. – Andrey Jun 30 '15 at 14:15

1 Answers1

0

Okay, one good guy helped me with that. Here's the working config:

   location /v2 {
        alias /home/example/api/v2/web;
        try_files $uri $uri/ /v2/index.php;
        location ~* \.(js|css|less|png|jpg|jpeg|gif|ico|woff|ttf|svg|tpl)$ {
            root /home/example/api/v2/web;
            expires 24h;
            access_log off;
        }
        location ~* /(.*) {
            include /etc/nginx/fastcgi_params;
            fastcgi_index  index.php;
            fastcgi_pass php56;
            fastcgi_param SCRIPT_FILENAME  /home/example/api/v2/web/index.php;
            fastcgi_param SCRIPT_NAME /v2/index.php;
        }
    }
Andrey
  • 201
  • 1
  • 2
  • 5