0

I'm trying to setup a location directive in nginx with an exact URI match of the form: http://host/authenticate/?username=test&password=test. I have a script called, index.php located in the public folder, /usr/share/nginx/html/authenticate/ which should process the query parameters that are sent. When I try a URI of the form http://host/authenticate/, my php script (index.php) processes the request. However, if the URI contains query parameters, http://host/authenticate/?username=blah&password=blah then I get 404 Not Found instead of index.php processing the request. Any thoughts on what I am doing wrong?

Much appreciated.

location = /authenticate/ { 
    index index.php;
    try_files $uri $uri/index.php$is_args$query_string =404;

#   fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_param USERNAME $arg_username;
    fastcgi_param PASSWORD $arg_password;

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root/authenticate/index.php;

    include fastcgi_params;
}
Malanie
  • 5
  • 2
  • Remove the `try_files` statement. – Richard Smith Jun 24 '20 at 19:43
  • @RichardSmith Removing the try_files statement yields "File not found" – Malanie Jun 25 '20 at 03:28
  • Try placing the `fastcgi_param SCRIPT_FILENAME $document_root/authenticate/index.php;` statement **after** `include fastcgi_params;` statement. – Richard Smith Jun 25 '20 at 06:17
  • @RichardSmith combining your 2 suggestions above did the trick. Thanks. – Malanie Jun 27 '20 at 07:09
  • The only issue now is that if I type http://host/authenticate/index.php?username=test&password=test the file index.php gets downloaded and not interpreted. Any suggestions? – Malanie Jun 27 '20 at 07:20
  • The `location` block in your question does not match the URI `/authenticate/index.php`. The `=` operator means that the `location` matches one and only one URI. The URI `/authenticate/index.php` is processed by a different `location` block. See [this document](http://nginx.org/en/docs/http/ngx_http_core_module.html#location). – Richard Smith Jun 27 '20 at 07:36
  • @RichardSmith It seems that not having a location block that captures uri requests to **/authenticate/index.php** is the reason that the file gets downloaded and not processed. – Malanie Jul 01 '20 at 06:12

0 Answers0