Nginx url rewrite rule problem

It looks like your’e missing the subdirectory part relative to the root setting, try this instead:

try_files $uri $uri/ /wordpress/index.php?$args;

and you shouldn’t need the q=$uri part.

For subdirectories dir1 and dir2, you could wrap the try_files with locate blocks, something like:

location /dir1/ { 
    try_files $uri $uri/ /dir1/index.php?$args; 
    #...
}

location /dir2/ { 
    try_files $uri $uri/ /dir2/index.php?$args; 
    #...
}