@Lloyd_mcse
You mentioned that you had two kinds of "solutions":
try_files $uri $uri/ /index.php?q=$request_uri; and
if (!-e $request_filename) { rewrite ^.*$ /index.php last;}
Actually, they are both concerning different topics or issues with WordPress (henceforth: WP).
Nevertheless, note the following:
a) the Nginx "try_files" directive is not necessary for a standard WP instance: the default Nginx configuration should work like a charm.
The fact that you have to specify the q variable, indicates two things: an issue with WP permalinks and the reason thereof, being "ugly" custom code that uses custom query variables (note: q is not a default WP query variable).
In short, your situation (in which the Nginx "try_files" directive) is required, is not a standard situation, applying to all WP instances.
b) Nginx is rather fussy about proper execution of directives and that requires that specific "bad things" should be prevented in Nginx configuration.
For instance, "if is bad" is a standard statement in the Nginx world: prevent any if in the Nginx configuration files.
The block
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
is rather strange: it contains an "if", a "rewrite" and a condition "if file exists".
Why strange? Well, note that
- Nginx checks file, directory and file extension pattern matches with location directives,
- Nginx allows "if" in location blocks,
and the above implies essentially that the specific location block has not been used to it´s full potential.
Why using the "if" statement then? Well, one seemed to observe the necessity to check for the existence of a specific file and return index.php if the file does not exist.
Again, WP is quite advanced and a proper functioning permalink setting will not require this "test and rewrite",
unless the permalink function is not working or broken by "ugly" code.
This (again) implies that your situation is not a standard situation, as noticed under point a.
Furthermore, the whole "if block" is bad practice from the Nginx perspective: just use a "try_files" directive, since that does the same "test and rewrite" more efficiently.
I hope that the above helps a bit in fine-tuning your Nginx configuration for the non-standard situation of your WP instance.
Regards....