• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question Help with Nginx configuration

zigojacko

Basic Pleskian
Ever since I can remember, when running domains with Nginx on a server with Plesk, I have to add the following to the Additional nginx directives section:

Code:
if (!-e $request_filename) {
    set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location)) {
    set $test "${test}C";
}
if ($test = PC) {
    rewrite ^/(.*)$ /index.php?$1;
}

This is with proxy mode off so it doesn't proxy requests to Apache.

Without these directives, any page other than the homepage on the website throws an Nginx 404 error.

But... I actually have no idea what exactly these directives are doing.

Please could someone advise:-

1) What do these directives to exactly?

2) Are they actually needed (or recommended)?

3) Is there or should there be another way of getting pages to display on sites without these directives?

This only seems to be an issue on servers running Plesk. Don't have the problem otherwise.
 
Setting variables like that is definitely not recommended as it apparently slows down nginx because it is not really compatible with the way nginx normally interprets the config files.
 
Setting variables like that is definitely not recommended as it apparently slows down nginx because it is not really compatible with the way nginx normally interprets the config files.
So why do inner pages only load when I add this? What does it do and how do you get Nginx to work in a Plesk environment without these?
 
So why do inner pages only load when I add this? What does it do
If the URL does not point to a file and the URL doesn't match any of the plesk or nginx internal locations, then call index.php with the local part of the URL.
Why it is done this way: Multiple if Conditions in Nginx If is Evil... when used in location context | NGINX
and how do you get Nginx to work in a Plesk environment without these?
  • Don't generate URLs that point to non-existing files
  • Use apache and the "usual" way of making these rewrites in .htaccess
 
If the URL does not point to a file and the URL doesn't match any of the plesk or nginx internal locations, then call index.php with the local part of the URL.
Why it is done this way: Multiple if Conditions in Nginx If is Evil... when used in location context | NGINX

  • Don't generate URLs that point to non-existing files
  • Use apache and the "usual" way of making these rewrites in .htaccess

Thanks for taking the time to reply.

This is just out-of-the-box WordPress sites for example with permalinks enabled. With default Nginx in Plesk, none of the URLs work except the homepage, probably as it tries to rewrite them to SEO-friendly versions.

I don't think a suggestion to use Apache with .htaccess is a great solution as it should be perfectly possible to use Nginx only which is what I want.

There has to be a way or a better approach to running WordPress websites with Nginx on a server running Plesk...? If I don't include those directives in the configuration then what should I be adding here instead?
 
Wordpress modifies the .htaccess by itself to make the redirects, among other things, work. Several plugins modify .htaccess too. So if you don't run a web server that makes use of that, you need to implement the necessary rewrites yourself.
As I understand, the Plesk way of running Wordpress like that is nginx->apache->php.
 
Wordpress modifies the .htaccess by itself to make the redirects, among other things, work. Several plugins modify .htaccess too. So if you don't run a web server that makes use of that, you need to implement the necessary rewrites yourself.
As I understand, the Plesk way of running Wordpress like that is nginx->apache->php.
@zigojacko (and @mow)

The quoted reply from @mow is fully correct.

In addition, @mow gives an alternative explanation of why one should not want to alter Nginx config : there are many plugins simply doing a lot of things to Apache web config and PHP config, implying that Nginx config has to be changed and optimized each time a plugin is added or updated.

In a perfect world, one can configure Nginx to bypass Wordpress or Wordpress plugin rewrites ...... but there is no perfect world in the context of Wordpress : in essence, most plugins are so buggy in terms of coding and configuration that a Nginx rewrite config will become unfeasible or even complete inefficient.

In my humble opinion, @zigojacko is full aware of the "less than perfect Wordpress world", given the statement

I don't think a suggestion to use Apache with .htaccess is a great solution as it should be perfectly possible to use Nginx only which is what I want.

since the .htaccess modifications are inherently associated with or the unavoidable result of Wordpress and its plugins.

However, there seems to be a misunderstanding of the function of Nginx and primarily the potential merits of Nginx.

In essence, @zigojacko aims to "misuse" Nginx to create rewrites (that are already present on the Apache level).

Nginx is by default constructed as a proxy (and later as a stand-alone web server), not as "URL rewrite machine".

Nginx should also be used as a proxy - it can do very well by serving images directly (and offloading Apache webserver).

Nginx could be used as a proxy with caching - it can do miracles to cache Wordpress generated pages (and hence again offloading Apache webserver).

In short, when using and configuring Nginx properly as a proxy, then most request are not even reaching the Apache level!

And having said that, then it also becomes immediately clear that messing with URL rewrites on the Nginx level would be strange - it is essentially removing Nginx as a proxy and creating the execution of tasks that are more or less identical and present on both the Nginx level and the Apache level.

It is highly recommend to

- leave Wordpress and its plugins for what they are,
- add Nginx as a proxy with caching mechanisms,
- use Nginx properly to reduce the traditional disadvantages of Wordpress and its plugins,

and miracles cannot be guaranteed : it still is Wordpress (read: inefficient) with plugins (read: arrrrrrrggggggggghhhhhh!)

I hope the above explains a bit and helps a bit!

Kind regards.......

PS @zigojacko - Plesk offers out-of-the-box caching mechanisms for Wordpress based sites, but you really need to adjust caching rules and configuration per site to get optimal results. In some cases, you even need to adjust Nginx default configuration. Nevertheless, the out-of-the-box caching mechanism can be a good start.
 
I've been using nginx as a native webserver for well over a year without ZERO issues on WordPress sites and I manage more than 300 sites over several Plesk servers.
They've changed the nginxvirtualdomain templates and now I cannot get my custom rules to work again. Your reply although true in some sense is not the reply wanted for someone who is wanting to use nginx in it's purest form.
There is NOTHING wrong trying to use nginx this way.

It is very pooor choice on Plesk end to just not provide enough documentation on how to properly use nginx as a native webserver.
I do not want to use it as a secondary cache/proxy, why would everyone need to comply to a single way of working with Plesk?.
 
Back
Top