NGINX - WORDPRESS - PHP-FPM: Query parameters (GET) not passing in subfolders

cn flag

I have a wordpress site running with NGINX (and Php-fpm) with 4 virtualhosts, everything works fine, except if i want to pass a query string. Look, it works if i do:

But it doesn't if i try

Here is my /nginx/snippets/wordpress.conf:

location = /favicon.ico {
    log_not_found off;
    access_log off;

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
    try_files $uri /index.php?$args;

location ~ /\. {
    deny all;

# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
# End Restrictions

# Caching
set $skip_cache 0;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
        set $no_cache 1;
if ($query_string != "") {
  set $skip_cache 1;

# Don't cache uris containing the following segments
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
  set $skip_cache 1;

# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
  set $skip_cache 1;
#end Caching

# WordPress single site rules.
location / {
    try_files $uri $uri/ /index.php?$args;
#location /wp-content/themes/kdi-ecommerce/templates/ {
#    try_files $uri $uri/ /index.php$is_args$query_string;

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(eot|otf|woff|woff2|ttf|rss|atom|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
    access_log off; log_not_found off; expires max;

# Media: images, icons, video, audio send expires headers.
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm)$ {
  expires 1M;
  access_log off;
  add_header Cache-Control "public";

# CSS and Javascript send expires headers.
location ~* \.(?:css|js)$ {
  expires 1y;
  access_log off;
  add_header Cache-Control "public";
# HTML send expires headers.
location ~* \.(html)$ {
  expires 7d;
  access_log off;
  add_header Cache-Control "public";

# Browser caching of static assets.
location ~* \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ {
  expires 7d;
  add_header Cache-Control "public, no-transform";

# Enable Gzip compression in NGNIX.
gzip on;
gzip_disable "msie6";

gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;

# Fast-CGI Cache configuration
location ~ \.php$ {
#location ~ [^/]\.php(/|$){
    #fastcgi_split_path_info ^(.+?\.php)(/.*)$;

    #if (!-f $document_root$fastcgi_script_name) {
    #    return 404;

    include fastcgi-cache.conf;
    include fastcgi.conf; 
    #fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_pass unix:run/php-fpm/www.sock;
    #enable cache
    add_header X-WP-Cache $upstream_cache_status;
    # Skip cache based on rules in snippets/fastcgi-cache.conf.
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;

    # Define memory zone for caching. Should match key_zone in fastcgi_cache_path above.
    fastcgi_cache restorebindemo;

    # Define caching time.
    fastcgi_cache_valid 60m;

    #PHP-FTP Buffers
    fastcgi_buffers 8 4k;
    fastcgi_buffer_size 8k;

    #increase timeouts
    fastcgi_read_timeout 60s;
    fastcgi_connect_timeout 60s;
    fastcgi_send_timeout 60s;

I have tried with all types of the try_files variations; i don't know if it's a location / block configuration.

Here is the fastcgi.conf:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

As is said, if i put the php file that i need to execute with parameters in the / (same place as the wp-config.php file) it works, but no in subdirectories.

il flag

You have:

  1. either to rewrite your path to the root, for example with own location for /subfolder/subfolder2/ or using rewrite directive:
rewrite ^/subfolder/subfolder2/([^/]+\.php)$ $1 last;
  1. or don't use fastcgi_split_path_info to split path, just try to supply the captured script name from location pattern, for instance add other location or rewrite your location ~ \.php$ like this:
- location ~ \.php$ {
+ location ~ ^/(?:subfolder/subfolder2/)?(?<script_name>[^/]+\.php)$ {
    fastcgi_param SCRIPT_NAME $script_name;

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.