Nginx Try_files redirection losing query string

I am trying to setup a specific redirection to force redirection to index.php (for Laravel) for a specific subdirectory, bypassing existing index.html.

The url i want to catch looks like this app/kit//?email= . In each directory there's a index.html file (and for some business reasons it's hard to change this)

The redirection seems to work, but when i parse $_SERVER in index.php, i lose the query string.

My Nginx configuration look like this:

server {
      server_name somedomain.com;
      root /home/www/preprod/current/public/;


        rewrite_log on;
        access_log /var/log/nginx/preprod-access.log;
        error_log /var/log/nginx/preprod-error.log notice;

        location ~* /kit/(.*)/index\.html {
              error_log /var/log/nginx/preprod-kit-error.log debug;
              try_files /index.php?$query_string /dev/null;
        }

      location / {
          index index.php index.html;
          try_files $uri $uri/ /index.php?$query_string;
          client_max_body_size 0;
          autoindex off;
          allow all;
      }

      location ~ \.php$ {
        error_log /var/log/nginx/preprod-php-error.log debug;
        #try_files $uri =404;
        #fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_intercept_errors off;
        fastcgi_connect_timeout 300s;
        fastcgi_read_timeout 15m;
        fastcgi_send_timeout 600s;
        fastcgi_keep_conn on;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        client_max_body_size 0;
        include snippets/fastcgi-php.conf;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
}

All the application works fine, except this one.

Edit 1: snippets/fastcgi-php.conf

# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;

# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

#fastcgi_index index.php;
include fastcgi.conf;
0
задан 12 June 2018 в 12:21
1 ответ

Я нашел решение, я использовал это:

 location ~* /kit/(.*)/(.*) {
        error_log /var/log/nginx/preprod.adsconsole.com-kit-error.log debug;
        rewrite /kit/(.*)/(.*) /index.php$is_args$args;
}

Регулярное выражение, очевидно, может быть лучше написано, но если оно может помогите кому-нибудь!

0
ответ дан 5 December 2019 в 05:54

Теги

Похожие вопросы