Applicable to:
- Plesk Onyx for Linux
Symptoms
-
nginx is enabled as the reverse proxy in Plesk.
-
If try adding the below directives in Plesk in Domains > example.com > Apache & nginx Settings > Additional nginx directives:
CONFIG_TEXT: location / {
..........
} -
The following error occurs:
PLESK_ERROR: Invalid nginx configuration: nginx: [emerg] duplicate location "/" in /data/www/system/example.com/conf/vhost_nginx.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed
Cause
Location /
is already defined in the main domain configuration file /var/www/vhosts/system/example.com/conf/nginx.conf
.
Resolution
Note: In the case that the additional directives that are needed to be added are for enabling Permalinks from Wordpress, please use this article: After switching a WordPress website to FPM served by nginx in Plesk, it fails to load with "404 Not Found" on all pages except start page
To add location /
to additional nginx directives:
See the below documentation article for more details:
Changing Virtual Hosts Settings Using Configuration Templates
Warning: The changes in the virtual hosts configuration templates are applied to all domains on the server.
-
In Domains > example.com > Apache & nginx directives temporary remove additional nginx directive containing
location /
; -
Disable Proxy Mode and click Apply;
-
Insert the necessary directive back into Additional nginx directives and click Apply.
Comments
8 comments
There is a bug: after deselecting checkbox Proxy mode, you must hit Save or Apply, and only after this step, you can add the directives, and save or apply again.
If you deselect the checkbox and add the directives in the same step, without an intermediate save or apply operation, you'll still get the error.
Hello @Marco Marsala,
Thank you for the feedback!
This behavior was reproduced in a test environment.
Currently, a request to the Development Team was created to clarify the nature of it.
We will update you as soon as we get any new information.
Hi @Marco Marsala,
This behavior was confirmed as a product bug with ID PPPM-9841, thank you for bringing our attention to it!
You can subscribe to the article below to get a notification when the bug will be fixed.
https://support.plesk.com/hc/en-us/articles/360014425974
As for a workaround - just disable Proxy Mode, save changes then insert the necessary directives and save changes again.
Not authorized to see the URL
@Marco Marsala
Please try again, it should be visible now.
I can define a custom `location /` but it will never match because the default nginx.conf contains:
location ~ /$ {
index "index.html" "index.cgi" "index.pl" "index.php" "index.xhtml" "index.htm" "index.shtml";
}
This will obviously match first, is there a way to disable this directive?
@Peter,
The issue you are speaking about, is described in this article. And in resolution section you could find that this default configuration could be overwritten using custom configuration templates.
@Konstantin Annikov templates are a major overkill for this problem. Use nested location instead:
location / {
proxy_pass http://127.0.0.1:3000;
...
location ~/$ {
proxy_pass http://127.0.0.1:3000;
...
}
}
Please sign in to leave a comment.