1

I have set up an Ubuntu 20.04 LEMP server with Wordpress, and am used some tutorials to help me configure Nginx. As of now, I have things functioning flawlessly, but in multiple Ubuntu "LEMP Server + Wordpress" tutorials, I noticed a single inconsistency in Nginx location block directives, and would like an explanation on the differences between each Nginx location directive:

In 1) Linuxbabe's LEMP Wordpress tutorial, he instructs to use the following location directive in my Nginx virtual host:

location / { try_files $uri $uri/ /index.php; } 

This broke things (the buttons wouldn't actually logout/empty-cart) with my Woo Commerce "Account Logout" button, as well as my Woo Commerce "Empty Cart" button, so it was not a solution for me.

In 2) this Devpress LEMP Wordpress tutorial he instructs to use the following location directive in my Nginx virtual host:

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

This fixed my Woo Commerce "Logout" and "empty-cart" buttons, and made them actually function and do what they are supposed to do.

In 3) this Digitalocean LEMP Wordpress tutorial he instructs to use the following location directive in my Nginx virtual host:

location / { try_files $uri $uri/ /index.php$is_args$args; } 

This ALSO fixed my Woo Commerce "Logout" and "empty-cart" buttons, and made them actually function and do what they are supposed to do.

So my question is, what is the difference between the

location / { try_files $uri $uri/ /index.php; } 

and

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

and

location / { try_files $uri $uri/ /index.php$is_args$args; } 

location directives in Nginx when using Wordpress with Woo Commerce?

Could you please elaborate and let me know why one of these broke Wordpress and two of them fixed it? Which one should I actually be using?

1 Answer 1

0

The difference is the variables used, so let's look at their documentation.

$is_args

? if a request line has arguments, or an empty string otherwise

$args

arguments in the request line

The $args does not contain the ? separator, so in this case the correct configuration would be:

location / { try_files $uri $uri/ /index.php$is_args$args; } 

So, why the $is_args is not simply included in $args? It becomes useful in a configuration where you would like to add an argument, e.g.,

try_files $uri $uri/ /index.php?lang=$geoip_country_code&$args; 

There, an additional ? would be an error. Adding the argument at the end of the string isn't an option either, because then there would be an empty ?& in case there weren't other arguments.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.