Question: Can't add "location /" to additional nginx directives in Plesk: nginx: [emerg] duplicate location "/"
Applicable to:
Plesk for Linux
Symptoms
Adding location / to Domains > example.com > Apache & nginx > Additional nginx directives fails
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
The location / is already defined in the main domain configuration file when nginx is set up as a reverse proxy.
Resolution
Note: If the directives are for enabling WordPress permalinks, use this article: 404 Not Found after switching WordPress to FPM by nginx
To add location / to additional nginx directives:
Disable nginx proxy mode
1.Log in to Plesk GUI
2.Go to Domains > example.com > Hosting & DNS > Apache & nginx directives
3.Temporarily remove the additional nginx directive that has location /
4.Disable Proxy Mode and click Apply
5.Go to Domains > example.com > Dashboard > PHP
6.Untick the box PHP support
7.Add the directive back to Additional nginx directives and click Apply
Create custom nginx config templates
The following documentation shows how to create custom templates for the virtual hosts:
Changing Virtual Hosts Settings Using Configuration Templates
Warning: The changes in the virtual hosts configuration templates are applied to all domains on the server.