Score:1

Difference between 3 similar Nginx Location Directives provided in three separate tutorials of the same topic

mx flag

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?

Score:0
jp flag

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.

mangohost

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.