drgawfsf1069 2018-06-12 13:06
浏览 317

Nginx Try_files重定向丢失查询字符串

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;
  • 写回答

1条回答 默认 最新

  • douqing5981 2018-06-12 13:34
    关注

    I found a solution,i used this :

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

    The regexp can obviously be better written, but if it can help someone !

    评论

报告相同问题?

悬赏问题

  • ¥15 html5+css有人可以帮吗?
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?