• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved Set Nginx reverse proxy configuration permanentely

Lars Lehmann

New Pleskian
We use nginx as a reverse proxy for directing the traffic of a subdomain to a specific port (11111 for example).

We can set this up in the nginx.conf file in the subdomains system config.

But always, when the subdomain is updated over plesk (when applying a new ssl certficate for instance), this conf file is overwritten and our custom configuration is lost. After this, our webapp is not accessible anymore and we need to change the file again.

My Question:
is it possible to make the following configuration or a similar permanent? (we also tried the Additional nginx directives, which doesn't work).

```
location / {
proxy_pass https://93.90.178.92:11111;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Accel-Internal /internal-nginx-static-location;
access_log off;
}
```
 
Thank you for your answer!

When I set a custom template, doesn't affect that all other (sub-) domains on our server as well?

And how should the template look like?
 
All new domains will be created based on this custom template.
 
But this is not what I wanted. I just want to reconfigure the 'location "/"' setting for some speciffic subdomains. Not for all or for all new upcoming ones.

Is there no other way?
 
Okay,
now I got a glimpse of a solution.

I used the vhost_nginx.conf configuration file an inserted the following:

location ~ / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass https://{{DOMAIN}}.de:{{PORT}};
}


It overwrites the configuration of Plesk.

This works perfect, but only if I manually remove the following from the nginx.conf file:

location ~ /$ {
index "index.html" "index.cgi" "index.pl" "index.php" "index.xhtml" "index.htm" "index.shtml";
}


I also cannot overwrite it like:

location ~ /$ {
proxy_pass https://{{DOMAIN}}.de:{{PORT}};
}



So, how can I permanentely remove the location ~ /$ {} from the nginx.conf or just overwrite it with my proxy?

Thank you!!!
 
I have the solution.
You can go into the "Apache and Nginx Settinngs" in a subdomain panel.

In the section of "Index files", set the option to "Enter custom value" and then replace the value of the textbox below with a simple space character " ".
If you don't put this space into the box, the option is not saved. But if you do so, then the nginnx is configured properly.

Very hacky, but it's working though.
 
Back
Top